Jump to content
  • Advertisement
Sign in to follow this  
Stormtrooper

OpenGL [SDL/OpenGL] Not drawing?

This topic is 4216 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is my first time using OpenGL, and I'm not sure why its not drawing anything... Drawing
int main(int argv, char *argc[])
{
	if(!initialize())
		return 0;

	graphics->beginScene();
	glBegin( GL_QUADS );
        // Top-left vertex (corner)
		glColor4ub( 255, 255, 255, 255 );
        glTexCoord2i( 0, 0 );
        glVertex3f( 100, 100, 0 );
    
        // Bottom-left vertex (corner)
        glTexCoord2i( 1, 0 );
        glVertex3f( 228, 100, 0 );
    
        // Bottom-right vertex (corner)
        glTexCoord2i( 1, 1 );
        glVertex3f( 228, 228, 0 );
    
        // Top-right vertex (corner)
        glTexCoord2i( 0, 1 );
        glVertex3f( 100, 228, 0 );
    glEnd();
	graphics->endScene();
	SDL_Delay(3000);

	return 0;
}
Init - returns true
	if(SDL_Init( SDL_INIT_VIDEO ) != 0)
	{
		return false;
	}
	
	// SDL Video Flags
	Uint32 videoFlags = SDL_OPENGL;
	if(fullscreen)
		videoFlags |= SDL_FULLSCREEN;
	
	// We want double buffering
	SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
	
	mScreen = SDL_SetVideoMode( width, height, 32, videoFlags );
	
	if(!mScreen)
	{
		return false;
	}

	// Color to clear to
	glClearColor( 0, 0, 0, 0 );	

	glViewport( 0, 0, mWidth, mHeight );
	
	return true;
void VideoDriver::beginScene()
{	
	//Set OpenGL State
	glEnable( GL_TEXTURE );
	glLoadIdentity();
	
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();
	
	glOrtho( 0, mWidth, mHeight, 0, -1, -1 );
	
	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();
	
	//glEnable( GL_SCISSOR_TEST );
	
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	
	// Clear the screen
	glClear( GL_COLOR_BUFFER_BIT );

}
void VideoDriver::endScene()
{
	// Swap Buffers
	SDL_GL_SwapBuffers();
}

Share this post


Link to post
Share on other sites
Advertisement
Do you load in a texture? Cos you have texture coords and enable texturing, but it'll presumably be using the default texture, which could be black, so you wouldn't see anything.

Share this post


Link to post
Share on other sites
Both the near and far planes are at -1! Your verts are probably at depth 0, which is bigger than the far plane (0 > -1), so they are getting clipped. Try moving the far plane to 1.

change this:
glOrtho( 0, mWidth, mHeight, 0, -1, -1 );

to this:
glOrtho( 0, mWidth, mHeight, 0, -1, 1 );

[edit]
BTW, the near and far planes should never be the same value - it will result in a division by zero in the projection matrix!

Share this post


Link to post
Share on other sites
A few suggestions I can think of off the top of my head:

try changing: glClear( GL_COLOR_BUFFER_BIT ); to glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

At the same time you're calling SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );, try also calling:
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );

Try changing the background color to red or some other bright color, just in case your primitives are being rendered black and so can't be seen. That's happened to me before, and it can happen for reasons you least expect.

try removing the glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); line.

And Hodgman is correct about glOrtho, I use the values he gave you for 2D rendering and it works great.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!