Page 1 of 1

OpenGL Failure

Posted: Mon Aug 20, 2012 9:08 am
by RandomDever
Here's the FULL source code:

Code: Select all

#include "SDL.h"
#include "SDL_opengl.h"

#pragma comment( lib, "SDL.lib" )
#pragma comment( lib, "SDLmain.lib" )
#pragma comment( lib, "OpenGL32.lib" )

int main( int num, char **blarg )
{
	SDL_Init( SDL_INIT_EVERYTHING );
	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_BUFFER_SIZE, 32 );
	SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 8 );

	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_DOUBLEBUFFER, 1 );
	glClearColor( 0.0F, 0.0F, 0.0F, 0 );
	glClearDepth( 1.0f );

	glViewport( 0, 0, 1280, 720 );
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();

	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();
	SDL_SetVideoMode( 1280, 720, 32, SDL_OPENGL );
	glOrtho( 0, 1280, 720, 0, 1, -1 );
	glEnable( GL_BLEND );
	glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
	while( 1 )
	{
		glClear( GL_COLOR_BUFFER_BIT );
		glLoadIdentity();
		glColor4ub( 255, 8, 8, 128 );
		glBegin( GL_QUADS );
		glVertex2f( 0.0F, 0.0F );
		glVertex2f( 1.0F, 0.0F );
		glVertex2f( 1.0F, 1.0F );
		glVertex2f( 0.0F, 1.0F );
		glEnd();
		SDL_GL_SwapBuffers();
	}
	SDL_Quit();
	return 0;
}
And this it what this code produces:
Image

I have no idea why it does this. Just FYI I believe I recently installed an updated video card driver so that may be the cause but IDK. Please help!

Re: OpenGL Failure

Posted: Mon Aug 20, 2012 9:22 am
by bbguimaraes
glOrtho should be called when the current matrix is set to GL_PROJECTION.

Re: OpenGL Failure

Posted: Mon Aug 20, 2012 11:49 am
by RandomDever
I can call that wherever I want and I still get the same result.

Code: Select all

#include "SDL.h"
#include "SDL_opengl.h"

#pragma comment( lib, "SDL.lib" )
#pragma comment( lib, "SDLmain.lib" )
#pragma comment( lib, "OpenGL32.lib" )

int main( int num, char **blarg )
{
	SDL_Init( SDL_INIT_EVERYTHING );
	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_BUFFER_SIZE, 32 );
	SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 8 );

	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_DOUBLEBUFFER, 1 );
	glClearColor( 0.0F, 0.0F, 0.0F, 0 );
	glClearDepth( 1.0f );

	glViewport( 0, 0, 1280, 720 );
	glMatrixMode( GL_PROJECTION );
	glOrtho( 0, 1280, 720, 0, 1, -1 );
	glLoadIdentity();
	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();
	SDL_SetVideoMode( 1280, 720, 32, SDL_OPENGL );
	glEnable( GL_BLEND );
	glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
	while( 1 )
	{
		glClear( GL_COLOR_BUFFER_BIT );
		glLoadIdentity();
		glColor4ub( 255, 8, 8, 128 );
		glBegin( GL_QUADS );
		glVertex2f( 0.0F, 0.0F );
		glVertex2f( 1.0F, 0.0F );
		glVertex2f( 1.0F, 1.0F );
		glVertex2f( 0.0F, 1.0F );
		glEnd();
		SDL_GL_SwapBuffers();
	}
	SDL_Quit();
	return 0;
}

Re: OpenGL Failure

Posted: Mon Aug 20, 2012 12:31 pm
by Nokurn
Don't call glLoadIdentity after glOrtho while you're still using the projection matrix. You're overwriting your orthographic projection matrix with the identity matrix. Call glLoadIdentity before glOrtho to avoid mixing ortho with the old projection matrix.

Re: OpenGL Failure

Posted: Sat Aug 25, 2012 11:32 am
by RandomDever
I changed that and it's still the same.
I had this working in my test game but then it just randomly stopped working but the VBOs still draw fine.

Re: OpenGL Failure

Posted: Sat Aug 25, 2012 12:12 pm
by GroundUpEngine
I'm guessing but try this:

Code: Select all

glVertex2f( -1.0F, -1.0F );
      glVertex2f( 1.0F, -1.0F );
      glVertex2f( 1.0F, 1.0F );
      glVertex2f( -1.0F, 1.0F );

Re: OpenGL Failure

Posted: Sat Aug 25, 2012 2:27 pm
by qpHalcy0n
Your state management looks absolutely atrocious. You have LoadIdentity's and PushMatrix's all over the place and in non-sensical places. I have no idea what you're trying to do, what it's supposed to do, or what other varieties of jacked up states you've got going on there from other places. .....but I could imagine. :]

Re: OpenGL Failure

Posted: Sat Aug 25, 2012 4:15 pm
by RandomDever
That just fills the whole screen.

Re: OpenGL Failure

Posted: Sat Aug 25, 2012 4:18 pm
by RandomDever
qpHalcy0n wrote:Your state management looks absolutely atrocious. You have LoadIdentity's and PushMatrix's all over the place and in non-sensical places. I have no idea what you're trying to do, what it's supposed to do, or what other varieties of jacked up states you've got going on there from other places. .....but I could imagine. :]
This was simply a test application, and is completely unoptimized. All I'm trying to do is make immediate mode draw correctly.
Also there are no 'other places'.
Main.cpp is the only file.

Re: OpenGL Failure

Posted: Sat Aug 25, 2012 6:15 pm
by qpHalcy0n
What is it you're trying to do?

Help us help you. I just see a picture of a red square on a black canvas. For all I know you want tons of red squares everywhere, maybe one big red square covering the whole screen, perhaps just a black screen.

No clue what it is you're doing here.

Re: OpenGL Failure

Posted: Sat Aug 25, 2012 8:39 pm
by RandomDever
Well the problem in the test app seems to have fixed itself. I thought I was having the same problem with the engine but IDK the screen setup code is fine. Here's the problem in the engine:
Can anyone explain what would cause immediate mode to not render?
Keep in mind that VBOs render perfectly.

Re: OpenGL Failure

Posted: Sun Aug 26, 2012 1:46 am
by qpHalcy0n
Poor render state or bad calls between a begin/end pair. Check for errors thrown by the GL. You don't know that its not rendering, but you do know it's not doing what you want. There's a big difference. Deprecation is possible, but I've yet to see a driver enforce it...