1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
#include "GL_Functions.h"
int InitGL(int Width, int Height, bool fullscreen)
{
int error;
//Initialise SDL, with everything
error = SDL_Init(SDL_INIT_EVERYTHING);
//The following 6 lines setup the openGL settings
//Setting up 32bit colour for the window
//And to use Double buffering
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
//This stores the information we want to initialise our display window with
//We want OpenGL and a Hardware surface so it will use the graphics card acceleration
//Binary OR is used to add all of the flags together
unsigned int flags = SDL_OPENGL | SDL_HWSURFACE | (fullscreen ? SDL_FULLSCREEN : 0);
//Set the Video mode, with the correct Width, Height, bitdepth (32bit) to match our
//OpenGL attributes we setup above.
SDL_SetVideoMode(Width, Height, 32, flags);
//Set the Clear Colour, this is the colour the window is cleared to as black
glClearColor(0.0, 0.0, 0.0, 0.0);
//Set the draw colour, to white.
glColor4f( 1,1,1,1);
//This is to setup an Ortho graphic projection. An ortho graphic projection has no perspective
//It setups the projection so its Width and height matches the screen.
//So 1 unit in world coordinates is 1 pixel on the screen.
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, Width, Height, 0.0, 0.0, 10.0);
//Enable 2 dimensional textures
glEnable(GL_TEXTURE_2D);
//Enable blending (transparencies) and setup the blend function correctly.
glEnable(GL_BLEND);
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
//This complex horrid mess disables V-Sync.
typedef void (APIENTRY * WGLSWAPINTERVALEXT) (int);
WGLSWAPINTERVALEXT wglSwapIntervalEXT = (WGLSWAPINTERVALEXT)
wglGetProcAddress("wglSwapIntervalEXT");
if (wglSwapIntervalEXT) {
wglSwapIntervalEXT(0); // disable vertical synchronisation
}
return error;
}
|