OpenGL Issue

Started by
7 comments, last by JTippetts 12 years, 5 months ago
Hiya,

I'm having some trouble drawing in OpenGL. I have a skybox working correctly, and I'm trying to get a triangle to draw - for some reason it fails, and I just see a skybox with nothing in front.

The code I'm using is:

/* Clear the buffers. */
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glLoadIdentity();

/* Draw the skybox if necessary. */
if(m_skyBox)
m_skyBox->draw();

gluLookAt(
0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 10.0f,
0.0f, 1.0f, 0.0f);

// static Mesh mesh("enemy.mesh");

// Zero the model/view matrix
glLoadIdentity();

// Translate the triangle to 0, 0, 10
glTranslatef(0.0f, 0.0f, 10.0f);

// Draw all white
glColor3f(1.0f, 1.0f, 1.0f);

// Draw the triangle vertices.
glBegin(GL_TRIANGLES); // Drawing Using Triangles
glVertex3f( 1.0f, 0.0f, 0.0f);
glVertex3f( 0.0f, 0.0f, 0.0f);
glVertex3f( 0.0f, 1.0f, 0.0f);
glEnd();

SwapBuffers(m_windowContext);


I must be doing something wrong... Any help would be appreciated! :)
Advertisement
A few things I see.

First of all make sure you disable z-buffering when you draw the skybox.

Also, it looks like you are doing the matrix operations out of order right after you draw the skybox.

Right now you do the lookat operation. Then loading and Identity. Loading an Identity clears any previous transformations so you probably want to switch those so you load the identity then do the gluLookAt
My current game project Platform RPG
Thanks very much :)
Just curious, any reason why you are using such an old OpenGL version?
I wasn't aware I was!

What makes you say that?
glBegin/End and the matrix stack/fixed function pipeline were removed after v2.1. We are currently on version 4.2.

http://www.opengl.org/documentation/current_version/
Well whaddaya know.

I've only used DirectX before, and this is for a university project. I'm definitely on a 'just make it work' deadline, so I'm just trying to learn what I can from tutorials as I go. I'll get a copy of the red book when this is finished, and take some time to look through it.

Anyways, thanks for the heads up. :)

Well whaddaya know.

I've only used DirectX before, and this is for a university project. I'm definitely on a 'just make it work' deadline, so I'm just trying to learn what I can from tutorials as I go. I'll get a copy of the red book when this is finished, and take some time to look through it.

Anyways, thanks for the heads up. :)


No problem! The good/bad thing about OpenGL is that when you start looking online for tutorials and help, you find a lot of old material thanks to the massive popularity of NeHe's legacy tutorials (I am willing to bet those are the ones you have been looking at).

Since they seemed to be rehosted at GameDev, it might be worth it to maybe go back and add a legacy disclaimer to the tut pages?
On an additional note, though, the "compatibility profiles" (ie, older GL versions) are still well supported by current drivers, and by upgrading to GL 4, you do run the risk of limiting your audience. I have a computer that is around 5 years old that only supports GL 2. I've also run into significant problems on newer computers with integrated Intel graphics having crappy GL 4 support. If your audience is going to be more of the "dedicated gamer" type, you can safely assume they have a fairly modern card of the ATI/NVidia variety with Vista/Win7 OS and GL 4 support. Outside of that rough demographic, it tends to be far more hit and miss. It'll sure be nice when you can count on GL 4 support, but that time is not right now.

This topic is closed to new replies.

Advertisement