PDA

View Full Version : vertices with coordinates < 1.0 being rounded to 0



Richard Schilling
07-18-2009, 02:07 PM
O.K. Just started doing serious OpenGL work. Greetings everyone.

I have a problem right off, and I can't find in any of the references I bought or on this forum. But, I expect it's a really easy problem.

I have a vertex array with the following points in it:

(-1.0, 1.0, -1.0)
(1.0, 1.0, -1.0)
(-1.0, -1.0, -1.0)
(1.0, -1.0, -1.0)

(-0.3, 0.3, -1.0)
(-0.4, 0.4, -1.0)

It's just a simple box, with a few points that coordiates with values < 1.0. The points that have whole numbers as their coordinates (1.0, -1.0) display just fine. The points with fractional coordinates get rounded down to (0.0, 0.0, 0.0).

It doesn't make sense as to why this would happen.

A day's worth of searching turned up no information about how OpenGL rounds float values down, or that there's a restriction on using whole numbers for coordinates. Or, an API call to get my points with numbers < 1.0 to show where they need to be.

Can someone please enlighten me on what I need to do to get a point to show up at, say (0.3, 0.3, -1.0)?

Thanks.

Richard Schilling

awhig
07-18-2009, 02:13 PM
For vertex display you might be using glVertex3i(); if so change 'i' to 'f'.

Richard Schilling
07-18-2009, 02:42 PM
Thanks for the reply.

I'm not using the glVertex, but rather vertex arrays:

gl.glVertexPointer(3, gl.GL_FIXED, 0, mVertexBuffer);

gl.glDrawArrays(GL10.GL_POINTS, 0, 22);

Of the 22 points being displayed, the five with whole number coordinates are displayed just fine, the rest appear at 0,0,0. Their actual coordinates are values that range from (0.1, 0.1, 0.1) to (0.9, 0.9, 0.9).

awhig
07-18-2009, 03:35 PM
Sorry I did not read that correctly. Did you try GL_FLOAT as type in glVertexPointer() as the following says:
http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/vertexpointer.html

dletozeun
07-18-2009, 04:27 PM
GL_FIXED looks Opengl ES like, I don't think it is supported on PC hardware assuming your are running your opengl program on a PC.

Richard Schilling
07-18-2009, 05:23 PM
Thanks for all the suggestions. Yes, it's Opengl ES.

I rewrote the routine to try to display the points using GL_FIXED and GL_FLOAT in my call to glDrawArrays(), and I set the point size to 3 using glPointSize(). I also cut out some unused objects that were hogging memory.

And, the points (both FIXED and FLOAT) suddenly started showing up correctly.

I don't know if the point size was just to small to see through all the dust and glare on my monitor, or if I was just being color blind, or if I was having a memory problem .... :-)

But, it's working now.

Cheers,

Richard

Xmas
07-20-2009, 04:44 AM
How did you initialize the fixed point data? Remember GLfixed is an integer type (and I guess with JSR-239/Android you use int directly), so if you use float data initally, make sure you multiply by 65536 before casting to int/GLfloat.