SDL 2.0 GL 3.3 no render

I am trying to use SDL 2.0 in my game engine to handle all the window related specifics, but i can't seem to be able to render anything to the screen :S

Relevant code:

Init:
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
log->logMessage(log->GL, "Initializing SDL");
	if (SDL_Init(SDL_INIT_VIDEO) < 0) /* Initialize SDL's Video subsystem */
	{
		log->logMessage(log->GLERR, "Could not initialize SDL!");
		log->logMessage(log->GLERR, SDL_GetError());
		return false;
	}

	log->logMessage(log->GL, "Setting SDL Attributes");
	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);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
    SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 2);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);

	log->logMessage(log->GL, "Setting SDL VideoMode");
	mainwindow = SDL_CreateWindow("Echoes Engine", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
        800, 600, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
    if (!mainwindow) /* Die if creation failed */
	{
		log->logMessage(log->WNDERR, "Could not create game window!");
		log->logMessage(log->WNDERR, SDL_GetError());
		return false;
	}
	SDL_GLContext maincontext;

	maincontext = SDL_GL_CreateContext(mainwindow);
	if(*SDL_GetError() != '\0')
	{
		log->logMessage(log->GLERR, "Could not create OpenGL context!");
		log->logMessage(log->GLERR, SDL_GetError());
		return false;
	}
	glViewport(0, 0, 800, 600);

	glOrtho(0, 800, 600, 0, 1, -1);
 
    glMatrixMode(GL_MODELVIEW);
 
    glLoadIdentity();
	glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
	log->logMessage(log->GL, "SDL and OpenGL successfully initialized");


And render:
1
2
3
4
5
6
7
8
9
10
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();
	glBegin(GL_TRIANGLES);
		glColor3f(1.0, 1.0, 1.0);
		glVertex3f(0.25, 0.25, 0.0);
		glVertex3f(0.75, 0.25, 0.0);
		glVertex3f(0.75, 0.75, 0.0);
	glEnd();

	SDL_GL_SwapWindow(mainwindow);


I am just trying to draw a simple triangle to the screen to make sure everything works, but it just wont draw anything *-*

*bump*
You need to select the projection matrix before calling glOrtho.
Last edited on
It does no diffrerence, i still don't get any render.
Topic archived. No new replies allowed.