]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Fixed timestep, added AA and a mouse cursor
authorAndy Belle-Isle <abelleisle@roadrunner.com>
Wed, 16 Sep 2015 02:16:34 +0000 (22:16 -0400)
committerAndy Belle-Isle <abelleisle@roadrunner.com>
Wed, 16 Sep 2015 02:16:34 +0000 (22:16 -0400)
src/main.cpp

index 3ae4206edbe75f82062a9c70acc54e23ffe2b76f..1843f4a87fddf9ecee791d86fba3ec6bc1e20ccd 100644 (file)
@@ -3,7 +3,7 @@
 #include <chrono>
 
 #define TICKS_PER_SEC 20
-#define MSEC_PER_TICK 500//(1000/TICKS_PER_SEC)
+#define MSEC_PER_TICK (1000/TICKS_PER_SEC)
 
 SDL_Window    *window = NULL;
 SDL_Surface   *renderSurface = NULL;
@@ -32,7 +32,7 @@ void render();
 
 unsigned int millis(void){
        std::chrono::system_clock::time_point now=std::chrono::system_clock::now();
-       return std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()).count();
+       return std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
 }
 
 int main(int argc,char **argv){
@@ -46,6 +46,9 @@ int main(int argc,char **argv){
                atexit(IMG_Quit);
                //Turn on double Buffering
         SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+        //ANTIALIASING!!!
+        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); 
+               SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 16);
         //create the window
         window = SDL_CreateWindow("Independent Study v.0.2 alpha", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL
                                   #ifdef FULLSCREEN
@@ -70,6 +73,7 @@ int main(int argc,char **argv){
        glViewport(0,0,SCREEN_WIDTH, SCREEN_HEIGHT);
        glClearColor(.3,.5,.8,0);
        glEnable(GL_BLEND);
+       glEnable(GL_MULTISAMPLE);
        glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
        SDL_ShowCursor(SDL_DISABLE);
        
@@ -185,11 +189,18 @@ void render(){
        **************************/
 
        //DRAW MOUSE HERE!!!!!W
-       glColor3ub(255,0,0);
        mx=(ui.mousex/(float)SCREEN_WIDTH)*2.0f-1.0f;
        my=((SCREEN_HEIGHT-ui.mousey)/(float)SCREEN_HEIGHT)*2.0f-1.0f;
        if(player.loc.x-1>-1)mx+=player.loc.x;
-       glRectf(mx,my,mx+HLINE*4,my+HLINE*4);
+
+       glBegin(GL_TRIANGLES);
+
+       glColor3ub(255,255,255);
+       glVertex2f(mx,my);
+       glVertex2f(mx + (HLINE*3.5),my - (HLINE*1));
+       glVertex2f(mx + (HLINE*1),my - (HLINE*6));
+
+       glEnd();
 
        glPopMatrix();                                                                  //take the matrix(s) off the stack to pass them to the renderer
        SDL_GL_SwapWindow(window);                                              //give the stack to SDL to render it