Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Another (simple) 3D question
#1
I'm trying to use OpenGL lists instead of creating objects every frame, using the following code:

Code:
glNewList u
        glBegin GL_TRIANGLES
                    glNormal3f 0.0, 0.0, 1.0
                    glColor3f o.p(i).colour, o.p(i).colour, o.p(i).colour
                      glVertex3f o.p(i).p1.x, o.p(i).p1.y, o.p(i).p1.z
                      glVertex3f o.p(i).p2.x, o.p(i).p2.y, o.p(i).p2.z
                    glVertex3f o.p(i).p3.x, o.p(i).p3.y, o.p(i).p3.z
        glEnd
glEndList

However, the first line doesn't work. It says "error 9: Expected expression", as though the glNewList function is not supported (even though glEndList works fine). Anyone know what's wrong & how to fix it?
Reply
#2
Hmm. I looked in gl.bi and found the sub declaration:

Code:
DECLARE SUB       glNewList ALIAS "glNewList" ( BYVAL list AS GLuint, BYVAL mode AS GLenum )

So it takes two parameters, not just one. But what is the mode parameter? I looked at some C++ code & it only had the list number.
Reply
#3
All problems resolved. Thanks for your help. 8)

The solution was to use GL_COMPILE as the second parameter & let OpenGL generate the list number thingy:

Code:
obj(i).list = glGenLists(1)
glNewList obj(i).list, GL_COMPILE
Reply
#4
Now I have another problem: I can't get texture mapping to work. I first use bload to load a 24-bit bmp (no problems there), but the last line in the following code block makes the program crash:

Code:
dim shared pic(64*64*2+4) as short
dim shared texture(64*64*2+4) as short
bload "zip.bmp", @pic(0)
'----
'do opengl init stuff here
'----
glGenTextures 1,varptr(texture(0))
glBindTexture GL_TEXTURE_2D, texture(0)
glTexImage2D GL_TEXTURE_2D, 0, 3, pic(0), pic(1), 0, GL_RGB, GL_UNSIGNED_BYTE, @pic(2)

Please help. :-?
Reply
#5
You have a couple of problems in your routine.
First, no need to reserve a whole new array for the GL texture... glGenTextures only needs a GLuint where to store the texture handle. Texture data is going to be uploaded to the VRAM!
Secondly, remember a GET/PUT array (such as the one returned by BLOAD in your case) has the image width times 8 in the first word, so to obtain the real width, you have to divide it by 8.

Have a look at gfxlib.txt, in appendix F there's a snippet that does exactly what you're trying to do here: create a GL texture out of a GET/PUT buffer. The same function is demo'ed in examples/GL/fbgfx_texture.bas
ngelo Mottola - EC++
Reply
#6
Well, I got the texture mapping to work, except that it reverses the red & blue values of the pixels (instead of a blue background, it's red). Please tell me I don't have to manually swap each pixel. :-?
Reply
#7
Yes you have, unless you use GL_BGRA as texture format (which is available only if you use OpenGL 1.2 or greater - Windows comes by default with GL 1.1 drivers, so you'd have to be sure your users all updated the drivers for their video card)
ngelo Mottola - EC++
Reply
#8
My image module will be finished soon. It includes a nice function that can convert images from any of the 8 formats to another one of those eight. (red, green, blue, grey, rgb, rgba, bgr, bgra).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)