GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: No Line Numbers


base code -> msdev.net by godecho
1
 
#ifdef _WIN32
    #pragma comment(lib, "glu32.lib")
    #pragma comment(lib, "opengl32.lib")
    #pragma comment(lib, "SDL.lib")
    #pragma comment(lib, "SDLmain.lib")    

    #include <windows.h>
#endif

#include <GL/gl.h>
#include <GL/glu.h>
#include <SDL/SDL.h>

bool keys[512];

void Draw(int TimePassed)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    glColor3f(1.0f, 1.0f, 1.0f);
}

void Init()
{

}

int main(int argc, char **argv)
{
    if(SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
    {
        fprintf(stderr, "SDL_Init() failed. SDL Error: %s\n", SDL_GetError());
        SDL_Quit();
        return false;
    }

    SDL_Surface *Surface = SDL_SetVideoMode(800, 600, 32, SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE | SDL_HWSURFACE | SDL_HWACCEL);

    if(!Surface)
    {
        fprintf(stderr, "SDL_SetVideoMode() Failed. SDL_Error: %s\n", SDL_GetError());
        SDL_Quit();
        return false;
    }

    glViewport(0, 0, 800, 600);
    glMatrixMode(GL_PROJECTION);
    gluPerspective(45.0f, float(800)/float(600), 0.1f, 500.0f);
    glMatrixMode(GL_MODELVIEW);

    Init();
    for(int i=0; i < 256; i++) keys[i] = false;

    int TimePrev = SDL_GetTicks(), TimeCurrent, TimePassed;
    while(1)
    {
        TimeCurrent = SDL_GetTicks();
        TimePassed  = TimeCurrent - TimePrev;

        Draw(TimePassed);
        SDL_GL_SwapBuffers();

        TimePrev = TimeCurrent;

        SDL_Event Event; SDL_PollEvent(&Event);
        if((Event.type == SDL_KEYDOWN && Event.key.keysym.sym == SDLK_ESCAPE) ||
           Event.type == SDL_QUIT) break;
        if(Event.type == SDL_KEYDOWN) keys[Event.key.keysym.sym] = true;
        if(Event.type == SDL_KEYUP) keys[Event.key.keysym.sym] = false;
    }

    return 0;
}