Changeset 18


Ignore:
Timestamp:
Jun 28, 2010, 12:25:25 AM (13 years ago)
Author:
sam
Message:

Move video initialisation stuff to a separate source file.

Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/.gitignore

    r17 r18  
     1*.o
    12src/test-map
  • trunk/src/Makefile

    r17 r18  
     1
     2SRC = test-map.cpp video.cpp
    13
    24all: test-map
    35
    4 test-map: test-map.cpp
    5         g++ -Wall -O3 $^ -o $@ `pkg-config --cflags --libs sdl gl SDL_image`
     6test-map: $(SRC:%.cpp=%.o)
     7        g++ -Wall -O3 $^ -o $@ `pkg-config --libs sdl gl SDL_image`
     8
     9%.o: %.cpp
     10        g++ -Wall -O3 -c $^ -o $@ `pkg-config --cflags sdl gl SDL_image`
    611
    712clean:
  • trunk/src/test-map.cpp

    r17 r18  
    1818#include <math.h>
    1919
    20 int frames;
     20#include "video.h"
    2121
    2222/* Storage for one texture  */
     
    5050{
    5151    glGenBuffers(3, buflist);
    52 }
    53 
    54 void InitGL(int Width, int Height)
    55 {
    56     // Resize method
    57     glViewport(0, 0, Width, Height);
    58     glMatrixMode(GL_PROJECTION);
    59     glLoadIdentity();
    60     glOrtho(0, Width, Height, 0, -1, 10);
    61     glMatrixMode(GL_MODELVIEW);
    62     glLoadIdentity();
    63 
    64     // Init method
    65     glEnable(GL_TEXTURE_2D);
    66     LoadGLTextures();
    67     MakeVBOs();
    68     glShadeModel(GL_SMOOTH);
    69     glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    70     glClearDepth(1.0);
    71     glEnable(GL_DEPTH_TEST);
    72     glDepthFunc(GL_LEQUAL);
    73     glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    74 
    75     glEnable(GL_BLEND);
    76     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    7752}
    7853
     
    192167    //glTranslatef(10.0f * sinf(0.16f * frames), 10.0f * cosf(0.16f * frames), 0.0f);
    193168    PutMap(l1objects);
    194 
    195     SDL_GL_SwapBuffers();
    196169}
    197170
    198171int main(int argc, char **argv)
    199172{
    200   SDL_Surface *video;
    201   int done;
    202 
    203   /* Initialize SDL for video output */
    204   if (SDL_Init(SDL_INIT_VIDEO) < 0)
    205   {
    206     fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError());
    207     exit(1);
    208   }
    209 
    210   /* Create a 640x480 OpenGL screen */
    211   video = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
    212   if (!video)
    213   {
    214     fprintf(stderr, "Unable to create OpenGL screen: %s\n", SDL_GetError());
    215     SDL_Quit();
    216     exit(2);
    217   }
    218 
    219   /* Set the title bar in environments that support it */
    220   SDL_WM_SetCaption("Deus Hax", NULL);
    221 
    222   /* Loop, drawing and checking events */
    223   InitGL(640, 480);
    224   done = 0;
    225   frames = 0;
    226   Uint32 ticks = SDL_GetTicks();
    227   Uint32 start = ticks;
    228   while (!done)
    229   {
    230     DrawScene();
    231     frames++;
    232 
    233     /* This could go in a separate function */
    234     SDL_Event event;
    235     while (SDL_PollEvent(&event))
    236     {
    237       if (event.type == SDL_QUIT)
    238         done = 1;
    239       if (event.type == SDL_KEYDOWN)
    240       {
    241         if (event.key.keysym.sym == SDLK_RETURN)
    242           SDL_WM_ToggleFullScreen(video);
    243         else if (event.key.keysym.sym == SDLK_ESCAPE)
    244           done = 1;
    245       }
     173    Video *video = new Video("Deus Hax", 640, 480);
     174
     175    int done;
     176
     177    /* Loop, drawing and checking events */
     178    LoadGLTextures();
     179    MakeVBOs();
     180
     181    done = 0;
     182    while (!done)
     183    {
     184        DrawScene();
     185
     186        video->Refresh(33.33333f);
     187
     188        /* This could go in a separate function */
     189        SDL_Event event;
     190        while (SDL_PollEvent(&event))
     191        {
     192            if (event.type == SDL_QUIT)
     193                done = 1;
     194            if (event.type == SDL_KEYDOWN)
     195            {
     196                if (event.key.keysym.sym == SDLK_RETURN)
     197                    video->FullScreen();
     198                else if (event.key.keysym.sym == SDLK_ESCAPE)
     199                    done = 1;
     200            }
     201        }
    246202    }
    247203
    248     while (SDL_GetTicks() < ticks + 33)
    249         SDL_Delay(1);
    250     ticks = SDL_GetTicks();
    251   }
    252   printf("%i fps\n", frames * 1000 / (SDL_GetTicks() - start));
    253   SDL_Quit();
    254 
    255   return EXIT_SUCCESS;
    256 }
    257 
     204    delete video;
     205
     206    return EXIT_SUCCESS;
     207}
     208
Note: See TracChangeset for help on using the changeset viewer.