Just starting with opengl and lwjgl

I’m using OS X, and am having two problems:

a) seems glRect* doesn’t draw anything. Lines work fine, I can draw a bitmap of a letter, and a gradient using a ByteBuffer. But it seems calling glRect* just doesn’t do anything. Tried disabling the texture, as suggested elsewhere. Is this an OS X bug?

b) I want to do double-buffering. Seems OS X likes drawing in back buffer, and seems to automatically swap buffers (eg calling swapbuffers has no effect). I assume from what I’m seeing (and read elsewhere), that OS X uses swap-copy - it copies the back buffer to the front, leaving the back untouched.

What I have is a rectanglular gradient I can drag around by moving the mouse.

It seems I can draw successive gradients, leaving “trails” on the screen, or I can erase the color buffer and redraw every time, but of course it flickers a bit. What I want to is kill the old gradient in the back buffer, but since glRect* doesn’t work, I can’t. (I suppose I could use a ByteBuffer of all black pixels if all else fails).

Am I missing something with double buffering, or are both of these problems the same problem - that glRect* simply doesn’t work on OS X?

LWJGL swaps the buffers on a call to Display.update(), I didn’t think that there was a swapbuffers() method directly accesible?

Have you tried doing equivilent drawing with glBegin(GL_QUADS)?

As Orangy Tang suggest, you should use glBegin(GL_QUADS) instead of glRect(). It’s more common and might be faster (and it gives the same result).

You should read some specifics OpenGL tutorials. Take a look at Nehe’s website. Surely the best place to start OpenGL and learn all you need !

Hope this helps.

Chman

The correct approach in OpenGL is to erase the backbuffer completely before rendering new data.

Under the hood, I have the strongest suspicion that all drivers just convert glRect calls into a glBegin(GL_TRIANGLE_STRIP) section anyway.

Cas :slight_smile:

Access to swapbuffers() is as follows:

Display.getImplementation().swapBuffers()

Thanks for the help, turns out in the end I just decided to erase and redraw
each frame, so I didn’t need the rect anyway, but I’ll try quads.