|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming | |
problem with openGL (c++)
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||||
|
New to Overclock.net
|
I'm trying to learn openGL and it's been going pretty well. I'm just following the code from a book and modifying it suit my application.
__________________I'm finally at the point where I can try my first polygon. Everything seems right and it all compiles correctly. The problem is that my window clears to white (which is correct) but nothing shows up. here is the code for the rendering function Code:
void Render()
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor (1.0f, 1.0f, 1.0f, 1.0f);
glLoadIdentity();
glPushMatrix();
glTranslatef (0.0f, 0.0f, 0.0f);
glBegin (GL_TRIANGLES);
glVertex3f (0.0f, 0.0f, 10.0f);
glVertex3f (0.0f, 1.0f, 10.0f);
glVertex3f (1.0f, 1.0f, 10.0f);
glEnd();
glPopMatrix();
SwapBuffers (g_Graphics.hDC);
}
|
|||||||||||||
|
|
|
|
|
#2 (permalink) | ||||||||||||||
|
With great difficulty
![]() |
Quote:
A few other notes (not as important). glClearColor shouldn't be called every time that Render is called, especially if it doesn't change, and it definitely should not be called after calling glClear. One call in your init function sets it until it changes (seems to be never in your case). Also, your glTranslate call doesn't do anything because it translates by 0 units in each direction. The last thing I'd mention is that it doesn't make much sense to push and pop the matrix if you aren't performing any transformations, and especially since you just set it to the identity every time Render is called anyway. You're saving the identity matrix, doing nothing to it, restoring it, then overwriting it with itself on the next pass.
|
||||||||||||||
|
|
|
|
#3 (permalink) | |||||||||||||
|
New to Overclock.net
|
I moved the GLClearColor into my init function and removed the translate and matrix stuff
__________________Code:
void Render()
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glBegin (GL_TRIANGLES);
glVertex3f (0.0f, 0.0f, -1.0f);
glVertex3f (0.0f, 1.0f, -1.0f);
glVertex3f (1.0f, 1.0f, -1.0f);
glEnd();
SwapBuffers (g_Graphics.hDC);
}
|
|||||||||||||
|
|
|
|
|
#4 (permalink) | |||||||||||||
|
With great difficulty
![]() |
You never set the drawing color with glColor. It's probably defaulting to whatever the clear color is
__________________
|
|||||||||||||
|
|
![]() |
| Tags |
| c++, graphics, opengl |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|