im just trying to draw a 2D square but its not working and i dont know y?
main.cpp
#include "sdl.h"
#include "GL_Functions.h"
int SDL_main(int argc, char* argv[])
{
//Used in the main loop
bool Done = false;
//Used to store SDL events
SDL_Event event;
//Lets open the window and initialise opengl
InitGL(1024,768);
while(!Done)
{
//Clear the screen
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_QUADS);
glColor3f(1,0,0);
glVertex2i(256, 128);
glColor3f(0,1,0);
glVertex2i(768, 128);
glColor3f(0,0,1);
glVertex2i(768, 640);
glColor3f(1,1,1);
glVertex2i(256, 640);
glEnd();
//Present that freshly drawn scene to the screen
SDL_GL_SwapBuffers();
//While we have events (keyboard, mouse, window etc)
while( SDL_PollEvent(&event) )
{
// if the window X was clicked on, ALT_F4 etc
if ( event.type == SDL_QUIT )
Done = true;
//If we have had a key press
if ( event.type == SDL_KEYDOWN )
{
//And the key was escape
if ( event.key.keysym.sym == SDLK_ESCAPE )
Done = true;
}
}
}
SDL_Quit();
return 0;
}
the GL_Functions.h
#ifndef _GL_FUNCTIONS_H_
#define _GL_FUNCTIONS_H_
//Includes for sdl, opengl, sdl_image
#include "sdl_opengl.h"
#include "sdl.h"
#include "sdl_image.h"
//Used to initialise SDL and OpenGL
int InitGL(int Width, int Height, bool fullscreen = false);
#endif
and the GL_Functions.cpp
#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;
}