Dark Bit Factory & Gravity
PROGRAMMING => General coding questions => Topic started by: Pixel_Outlaw on January 04, 2008
-
I've never had much problem rotating things in OpenGL but I've been away from my redbook for a while.
Some time ago I made a crude primatives library. The call draws a shape around point (0,0,0).
I wanted to simply draw a cyllindar rotated along the z axis 90 degrees.
Instead, if I use glloadidentity() nothing is drawn, if I leave it out the shape just spins like mad. I really hate to post here for such a simple question. I've looked around a bit first and I know that usually you call loadidentity,translate and then rotate in that order.
Strict
Include "shapes.bmx" ' my old primatives library
GLGraphics 800, 600
glEnable(GL_DEPTH_TEST)
glShadeModel(GL_FLAT)
glOrtho(0, 800, 600, 0, 1000, - 1000)
glClearColor(.25, .25, .25, 1)
While Not KeyDown(KEY_ESCAPE)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
glTranslatef(400.0, 300.0, 0.0)
glRotatef(90.0, 0.0, 0.0, 1.0)
draw_tube(36.0, 1.0, 480.0, 200.0, 1.0)
Flip
Wend
-
hint: glMatrixMode
Jim
-
I guess I need some more time in learning how the matrix systems work. Probably some of that pushing and popping tomfoolery.
-
Sorry, was on my PSP so that was the least information I thought I could get away with.
I'd try this
Strict
Include "shapes.bmx" ' my old primatives library
GLGraphics 800, 600
glEnable(GL_DEPTH_TEST)
glShadeModel(GL_FLAT)
[b]glMatrixMode(GL_PROJECTION)[/b]
glOrtho(0, 800, 600, 0, 1000, - 1000)
glClearColor(.25, .25, .25, 1)
[b]glMatrixMode(GL_MODELVIEW)[/b]
While Not KeyDown(KEY_ESCAPE)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
glTranslatef(400.0, 300.0, 0.0)
glRotatef(90.0, 0.0, 0.0, 1.0)
draw_tube(36.0, 1.0, 480.0, 200.0, 1.0)
Flip
Wend
The first call I added says - all transforms from now on apply to the projection matrix which you then set by glOrtho.
The second call says - all transforms from now on apply to the modelview matrix, which you reset by calling glLoadIdentity and then glTranslate, glRotate.
Jim
-
Ah thanks! I didn't know that glortho had to follow setting the matrix mode.