Rotation makes stuff disappear?

Started by
9 comments, last by Kalidor 18 years, 9 months ago
I'm new to OpenGL and I'm trying to figure out how to rotate one object without rotating the whole scene. From looking at MSDN I figured I should be doing something like this:

glPushMatrix();
glRotatef(20f, 0.0f, 1.0f, 0.0f);

glBegin(GL_LINES);
    //Draw my object
glEnd();

glPopMatrix();
Then that way only what I draw in the glBegin block would be rotated. But when I do this my object doesn't render at all! It's just a square with a textured on it if that makes a difference. What am I doing wrong?
Advertisement
glBegin(GL_LINES); ?

If you want to draw poly's, you might want to use "GL_QUADS" or something other than lines and points. Also, if you're drawing in 3D, remember to use normals. I'm pretty new to OpenGL myself, but that's all I can tell that you might be mistaken on.

[edit] also, why are you using matricies? I'm not sure of the rest of the code you've got going on there, but I'd suggest looking at any of the tutorials, especially the NeHe tutorials on the site; they're pretty good for the simple stuff we're learning.
Quote:Original post by ciroknight
glBegin(GL_LINES); ?

If you want to draw poly's, you might want to use "GL_QUADS" or something other than lines and points. Also, if you're drawing in 3D, remember to use normals. I'm pretty new to OpenGL myself, but that's all I can tell that you might be mistaken on.


Except, I'm actually drawing lines :)

Quote:also, why are you using matricies? I'm not sure of the rest of the code you've got going on there, but I'd suggest looking at any of the tutorials, especially the NeHe tutorials on the site; they're pretty good for the simple stuff we're learning.


Um, it's OpenGL, how can you avoid using matrices? ;)

If you mean the push/pop stuff, that's what MSDN made it sound like I should do if I only want to rotate one object.

NeHe's tutorials as far as I can tell don't really address my question. He gets rotation working by reloading the identity and moving to a new point. Since all my drawing takes place from the same position, I'm not sure that makes sense for me. Meh, I'll fiddle with the code tomorrow, resetting the identity may fix it.
Quote:Original post by Jengu
If you mean the push/pop stuff, that's what MSDN made it sound like I should do if I only want to rotate one object.


You seem to use push and pop correctly. They make sure that the rotation is not applied to anything drawn after the pop statement.

Quote:Original post by Jengu
It's just a square with a textured on it if that makes a difference.

Except, I'm actually drawing lines :)

These two statements are a bit confusing. Do you really want only four lines with texture on them? Are you using a 1D texture?

Anyway, the code you have given is not enough to answer your question. Are you sure that the missing quad is caused by the rotation (i.e. is the quad visible if you comment the glRotate(...) line?)?

Tom
if you draw a poligon where every x or every z are in the same plane. when rotate it about y axis it would disssapear the solution is to use volumetric poligons where you must draw the poligon and add volume to it like (cones,spheres....) or rotate the camera on the same angle as the object.

All depends what you really want.
Are you applying that transformation to the ModelView matrix?
perhaps the current matrix on the stack is the projection from your setup code?

before that glPushMatrix() try a call to glMatrixMode(GL_MODELVIEW).

a rotation of 20 degrees shouldn't cause the object to vanish (if backface culling is enabled) due to culling (assuming that you draw the polygon with 0 rotation to begin with - i.e. it's screen aligned).

as a poster above pointed out, your use of lines is weird.

try a GL_TRIANGLES and pass 3 vertices.

a larger code snippet would help.
Quote:Original post by Jengu
glPushMatrix();glRotatef(20f, 0.0f, 1.0f, 0.0f);glBegin(GL_LINES);    //Draw my objectglEnd();glPopMatrix();
Are you drawing your object around the origin? All rotations occur about the current origin, so if you're not rendering the object some distance away from the origin it could easily be rotating off the screen.

If you haven't already, I suggest implementing some simple camera controls so you can look around.
Doh, forgot about the texture. See, my app does actually use GL_LINES at one point. But in this case the object that's disappearing is actually a GL_QUAD. Managed to confuse myself. Sorry :P

Commenting out the glRotate line does make the object reappear.

I used glOrtho2D so that my windowing systems coordinates and my OpenGL coordinates match up because I'm doing a lot of 2D drawing. So the origin (0,0) is the top left of the screen. The object I'm trying to rotate is at the center of the screen so it's at some positive x and positive y value. I think this is what is somehow screwing it up.

Putting glMatrixMode(GL_MODELVIEW) before the push doesn't do the trick either. :/

Here's how I setup the gl view:

void PageCanvas::OnSize(wxSizeEvent& event){	// Now resetup OpenGL coordinates	int width, height;	GetClientSize(&width, &height);	if(GetContext())	{		SetCurrent();		glViewport(0, 0, (GLint)width, (GLint)height);	}	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	gluOrtho2D (0.0, (GLdouble) width, (GLdouble) height, 0.0);	glMatrixMode(GL_MODELVIEW);	glLoadIdentity();}
well if none of these other answers get it working for you then the most likely problem is that you are drawing in a clockwise order and are culling backfaces, meaning you are culling what are you drawing. if none of this other stuff works, that may be your problem.
It seems you've mixed up your parameters to gluOrtho2D.

the third parameter is the bottom (which should be 0) and the forth parameter is the height.

This is probably causing your polygons to be drawn as if there's a scaling of -1 along the y axis - effectively reversing your winding.

if you have GL_CULL_FACE enabled then you're culling your polygons.

explicitly disable face culling with a glDisable(GL_CULL_FACE) and fix your gluOrtho call.

This topic is closed to new replies.

Advertisement