openGL/sdl

im just trying to draw a 2D square but its not working and i dont know y nothing coming up on the screen
main.cpp

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
#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

1
2
3
4
5
6
7
8
9
10
11
12
#endif#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



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;

}


can someone tell me what im doing wrong
Last edited on
First thing that comes to mind is that you have texures enabled, but no texture selected. I'm not sure how OpenGL behaves in that instance, but it's possible you're rendering an all-black textured quad onto a black screen (thus it's not showing)

I'd try disabling textures and see if that helps.

1
2
3
4
5
6
7
8
9
		glDisable(GL_TEXTURE_2D);  // <== disable textures

		//Clear the screen
		glClear(GL_COLOR_BUFFER_BIT);


		glBegin(GL_QUADS);

//... 
Topic archived. No new replies allowed.