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:: Add Line Numbers


SDL openGL by Zaka
#include <windows.h>
#include "SDL/SDL.h"
#include <gl\GL.h>    // Header File For The OpenGL32 Library
#include <gl\GLU.h> // Header File For The GLu32 Library
#include <gl\GLAux.h>

#include "Game.h"
#include "main.h"

#define H_SCREEN    1280
#define V_SCREEN    1024
#define COLOR_DEPTH 32

SDL_Surface *screen;
int flags = SDL_OPENGL | SDL_FULLSCREEN | SDL_DOUBLEBUF;
int running = 1;

int main( int argc, char* args[] )
{
    //Start SDL
    SDL_Init( SDL_INIT_EVERYTHING );

    createScreen();
    Init_Opengl();
    GLDraw();
////////////////////////SDL-LOOP//////////////////////////
    SDL_Event event;
     
    while(running) {

                                game();

        while(SDL_PollEvent(&event)) {
            switch(event.type){
                case SDL_KEYDOWN:
                    if(event.key.keysym.sym==SDLK_ESCAPE)
                    running = 0;
                    break;
                case SDL_KEYUP:
                    break;
            }
        }
    }
//////////////////////////////////////////////////////////


    SDL_Quit();
    
    return 0;    
}
void createScreen()
{
    SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
    SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
    SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
    SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 32 );
    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
    screen = SDL_SetVideoMode(H_SCREEN, V_SCREEN, COLOR_DEPTH, flags );
    if ( screen == NULL ) {
        fprintf(stderr, "Not possibile to use resolution 1280 X 1024: %s\n",
                 SDL_GetError());
        exit(1);
    }
}
void Init_Opengl()  // all initialization parameters...
{
    glMatrixMode(GL_PROJECTION | GL_MODELVIEW);
    glLoadIdentity();
    glClearColor ( 0.0, 0.0, 0.0, 0.0 );
    glClear ( GL_COLOR_BUFFER_BIT );
    glDepthFunc(GL_LEQUAL);
    glShadeModel(GL_SMOOTH);
    glDisable(GL_CULL_FACE);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    glOrtho ( -6.25, 6.25, -5.0, 5.0, -1.0, 10.0 );
}
void GLDraw()
{
    glBegin ( GL_POLYGON );
        glColor3f (0.5f , 0.2f , 0.7f);
        glVertex3f (-0.2, -0.2, 0.0);
        glVertex3f (0.2, -0.2, 0.0);
        glVertex3f (0.2, 0.2, 0.0);
        glVertex3f (-0.2, 0.2, 0.0);
    glEnd();
    SDL_GL_SwapBuffers();
    glFlush();
}