• Advertisement
Sign in to follow this  

OpenGL makes my head hurt

This topic is 3231 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

I just started a new project (2D OpenGL). I have a screen running, and OpenGL is initialized. I tried different clear colors to test that. But I can't get a simple rectangle to appear. Here's some of the code:
// initialization
::wglMakeCurrent( hdc_, hrc_ );
::glViewport( 0, 0, width_, height_ );

::glShadeModel( GL_SMOOTH );
::glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
::glClearDepth( 1.0f );
::glEnable( GL_DEPTH_TEST );
::glDepthFunc( GL_LEQUAL );
::glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );

::glMatrixMode( GL_PROJECTION );
::glLoadIdentity();
::glOrtho( x, x + current_->width_, y + current_->height_, y, -1.0, 1.0 );
::glMatrixMode( GL_MODELVIEW );
::glLoadIdentity();

// loop code
::glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
::glLoadIdentity();

::glColor3f( 1.0f, 0.0f, 0.0f );
::glBegin( GL_QUADS );
  ::glVertex3f( 0.0f, 0.0f, 0.0f );
  ::glVertex3f( 0.0f, 240.0f, 0.0f );
  ::glVertex3f( 320.0f, 240.0f, 0.0f );
  ::glVertex3f( 320.0f, 0.0f, 0.0f );
::glEnd();

::SwapBuffers( current_->hdc_ );

I'm a gl n00b. Are there any obvious mistakes here? EDIT: x and y are both 0, and width and height are 640,480.

Share this post


Link to post
Share on other sites
Advertisement
Try changing:

glViewport( 0, 0, width_, height_ );

to

glViewport( 0, 0, current_->width_, current_->height_ );

I have no idea if that'll actually work, but I notice you use width_ and height_ in one place and current_->width_ and current_->height_ elsewhere.

And yeah, I sympathise with your opengl pains. I haven't touched it in ages.

Share this post


Link to post
Share on other sites
Quote:
Original post by gharen2
Try changing:

glViewport( 0, 0, width_, height_ );

to

glViewport( 0, 0, current_->width_, current_->height_ );

I have no idea if that'll actually work, but I notice you use width_ and height_ in one place and current_->width_ and current_->height_ elsewhere.

And yeah, I sympathise with your opengl pains. I haven't touched it in ages.


This code is completely out of context. I used current_ in static functions. I wish OpenGL was more verbose with errors. glGetError always returns GL_INVALID_OPERATION for me.

EDIT: Well it used to return GL_INVALID_OPERATION, but apparently it returns 0 now. But still nothing appears on the screen.

[Edited by - Daggerbot on April 18, 2009 2:54:23 AM]

Share this post


Link to post
Share on other sites
Since you see the correct clear color I assume that buffer swapping works well. It would be useful to see also the rendering code, because the problem may be there, too.

Which of OpenGL's routines returns the GL_INVALID_OPERATION?

Share this post


Link to post
Share on other sites
Er, I'm gonna go sleep right now so what I say may be non-sense, and I didn't check the code carefully, but a question: did you enable depth masking somewhere? (glDepthMask(GL_TRUE)) It seems that the depth buffer doesn't get cleared if depth writing isn't enabled (I don't feel like checking the specs to see if that's normal behaviour =P), so maybe you're getting the rectangle culled out by the depth buffering.

Make sure to add it before glClear(), by the way =b

Share this post


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

  • Advertisement