OpenGL Failure

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
RandomDever
Chaos Rift Regular
Chaos Rift Regular
Posts: 198
Joined: Thu Mar 26, 2009 8:42 pm
Current Project: My Engine
Programming Language of Choice: C++

OpenGL Failure

Post 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!
User avatar
bbguimaraes
Chaos Rift Junior
Chaos Rift Junior
Posts: 294
Joined: Wed Apr 11, 2012 4:34 pm
Programming Language of Choice: c++
Location: Brazil
Contact:

Re: OpenGL Failure

Post by bbguimaraes »

glOrtho should be called when the current matrix is set to GL_PROJECTION.
RandomDever
Chaos Rift Regular
Chaos Rift Regular
Posts: 198
Joined: Thu Mar 26, 2009 8:42 pm
Current Project: My Engine
Programming Language of Choice: C++

Re: OpenGL Failure

Post 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;
}
User avatar
Nokurn
Chaos Rift Regular
Chaos Rift Regular
Posts: 164
Joined: Mon Jan 31, 2011 12:08 pm
Favorite Gaming Platforms: PC, SNES, Dreamcast, PS2, N64
Programming Language of Choice: Proper C++
Location: Southern California
Contact:

Re: OpenGL Failure

Post 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.
RandomDever
Chaos Rift Regular
Chaos Rift Regular
Posts: 198
Joined: Thu Mar 26, 2009 8:42 pm
Current Project: My Engine
Programming Language of Choice: C++

Re: OpenGL Failure

Post 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.
User avatar
GroundUpEngine
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 835
Joined: Sun Nov 08, 2009 2:01 pm
Current Project: mixture
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: UK

Re: OpenGL Failure

Post 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 );
qpHalcy0n
Respected Programmer
Respected Programmer
Posts: 387
Joined: Fri Dec 19, 2008 3:33 pm
Location: Dallas
Contact:

Re: OpenGL Failure

Post 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. :]
RandomDever
Chaos Rift Regular
Chaos Rift Regular
Posts: 198
Joined: Thu Mar 26, 2009 8:42 pm
Current Project: My Engine
Programming Language of Choice: C++

Re: OpenGL Failure

Post by RandomDever »

That just fills the whole screen.
RandomDever
Chaos Rift Regular
Chaos Rift Regular
Posts: 198
Joined: Thu Mar 26, 2009 8:42 pm
Current Project: My Engine
Programming Language of Choice: C++

Re: OpenGL Failure

Post 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.
qpHalcy0n
Respected Programmer
Respected Programmer
Posts: 387
Joined: Fri Dec 19, 2008 3:33 pm
Location: Dallas
Contact:

Re: OpenGL Failure

Post 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.
RandomDever
Chaos Rift Regular
Chaos Rift Regular
Posts: 198
Joined: Thu Mar 26, 2009 8:42 pm
Current Project: My Engine
Programming Language of Choice: C++

Re: OpenGL Failure

Post 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.
qpHalcy0n
Respected Programmer
Respected Programmer
Posts: 387
Joined: Fri Dec 19, 2008 3:33 pm
Location: Dallas
Contact:

Re: OpenGL Failure

Post 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...
Post Reply