Author Topic: Why is this VERY simple rotation not working in OpenGL?  (Read 2999 times)

0 Members and 1 Guest are viewing this topic.

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile


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.


Code: [Select]
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
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
hint: glMatrixMode

Jim
Challenge Trophies Won:

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
I guess I need some more time in learning how the matrix systems work. Probably some of that pushing and popping tomfoolery.
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Sorry, was on my PSP so that was the least information I thought I could get away with.
I'd try this
Code: [Select]
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
Challenge Trophies Won:

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
Ah thanks! I didn't know that glortho had to follow setting the matrix mode.
Challenge Trophies Won: