PDA

View Full Version : Weird Drawing Behavior



chrisjon
01-15-2009, 11:29 AM
I am working on a 3D rendering program that is showing some odd behavior in one scenario. An object is drawing completely distorted like some verticies have incorrect values. If I change the shade model from flat to smooth the problem goes away. Also if I disable hardware acceleration it goes away.

It is drawn with a display list of many triangles. I dumped all opengl calls and here is the beginning of the display list:

glNewList(30,GL_COMPILE)
glBegin(GL_TRIANGLES)
glNormal3s(14176,-27392,11008)
glVertex3fv([745.645996,-110.776863,533.855957])
glVertex3fv([746.505310,-110.517570,533.392639])
glVertex3fv([746.044861,-110.258606,534.631165])
glNormal3s(1344,-21472,-24704)
glVertex3fv([685.436279,-111.156952,463.180542])
glVertex3fv([684.565857,-110.500710,462.562866])
glVertex3fv([685.952454,-110.293732,462.458679])
glNormal3s(4640,-32320,-2432)
glVertex3fv([685.952454,-110.293732,462.458679])
glVertex3fv([684.565857,-110.500710,462.562866])
glVertex3fv([685.285828,-110.314262,461.483887])

Does anyone have any idea of what could be happening or how I could figure out what is going on? Thanks in advance!

chrisjon
01-15-2009, 11:30 AM
By the way, I am running Windows XP and I have an NVIDIA Quadro Fx 570 graphics card.

dletozeun
01-15-2009, 11:45 AM
Why do you use short type to represent normal vectors?

When you set smooth shade model, fragment color is the result of the face vertices color interpolation, otherwise fragment color is set by one of the vertices color. So when you set normals you should set smooth shading using the fixed pipeline.

chrisjon
01-15-2009, 11:52 AM
I use short normals to save memory since I can have millions of triangles in some cases.

"So when you set normals you should set smooth shading using the fixed pipeline" - could you explain this a little more, I don't follow?

thanks.

dletozeun
01-15-2009, 12:07 PM
Aah, I did not see you set normals per triangle :). So with flat or smooth shading it would not change anything. Is it possible to have a screenshot of the problem?
Are you sure your normals are correctly normalized? You can ask opengl to do it for you with glEnable(GL_NORMALIZE) is your display list to see if it changes something.

chrisjon
01-15-2009, 12:18 PM
I am having trouble pasting an image (screenshot) into the post, is there a way I am suppose to do it or a way to attach an image?

I will try adding glEnable(GL_NORMALIZE) to see if it changes anything. I left it out since the normals are (suppose to be) already normalized.

chrisjon
01-15-2009, 12:22 PM
GL_NORMALIZE did not change it...

chrisjon
01-15-2009, 01:12 PM
I found why it was working with smooth shading. It is because smooth shading takes a different code path in my program that does not use a display list. So if I draw it using a display list it is becoming distorted but if I draw without one it draws fine. Any ideas???

ZbuffeR
01-16-2009, 01:38 AM
display list or not should not change anything.
probably your different code paths also have different bugs.

dletozeun
01-16-2009, 05:51 AM
you can upload the screenshots on a hosting site like this one (http://imageshack.us/), then copy and paste the url they give to you in your post, it should work then.

Zbuffer is right, it should be something in your code. Is it possible to have the relevant code instead of dumped opengl calls?