PDA

View Full Version : rendering problems



Rocketman
02-17-2010, 02:53 PM
Hello,

I have a problem which I cannot seem to solve. When I render my image, it should be smooth. However, I am getting a messy rendering which looks like there is some sort of grid ontop of it - as seen in the screenshot below.

http://img294.imageshack.us/img294/4319/11501714.jpg

Basically it's a fairly simple program. I am plotting a large list of vertex, calculating the normal vector for each polygon and adding ambient light.

Could it be my normals are not facing the right direction?

Cheers,
Dave

Rocketman
02-18-2010, 05:44 AM
I tried using glNormal3f() before defining three glVertex3f().as opposed to the other way around.

The image improved slightly, but still seems wrong :(

http://img39.imageshack.us/img39/4192/53524398.jpg

Could anyone suggest if this is a lighting problem? i.e. my normals are wrong, or are my vertex/polygons likely to be wrong

thanks

ZbuffeR
02-18-2010, 06:07 AM
glNormal, as glColor etc, must be called before its glVertex.
Otherwise, yes, it looks like you do not specify normals correctly, for some parts.

As a check, try setting always the same normal, for all vertices : you should ge a fairly uniform color. In that case, you only have aproblem with normals. Otherwise, something is wrong with vertices too.

Rocketman
02-18-2010, 06:15 AM
Hi, thanks for the help.

I tried just using glNormal3f(1.0f,1.0f,1.0f) and I'm getting my image in a plain grey colour.

Can I just ask something. I have polygons made up of three vertices. I am currently doing something like this:

glNormal3f(1.0f,0.0f,1.0f);
glVertex3f(vertex[poly1][0],vertex[poly1][1],vertex[poly1][2]);
glVertex3f(vertex[poly2][0],vertex[poly2][1],vertex[poly2][2]);
glVertex3f(vertex[poly3][0],vertex[poly3][1],vertex[poly3][2]);

Is it right that I have one normal for three vertex3f() calls?

Cheers

ZbuffeR
02-18-2010, 07:25 AM
Using only one normal for a triangle will give you flat shading.
But that does not explain the weird image you get...

To have smooth shading, a vertex shared by all is adjacent triangles should have a normal somewhat averaging the triangles normals.

Rocketman
02-18-2010, 09:57 AM
When I change GL_POLYGON to GL_TRIANGLES, I get this.
http://img11.imageshack.us/img11/6892/71767634.jpg
I thought a polygon with three points was the same as a triangle.

Actually, it seems like my problems are coming from this line:

gluPerspective(45, 1, 0, 10);

If I comment out that line, I get a correct rendering!, but only with GL TRIANGLES, not GL POLYGON. I heard somewhere that polygon is not good for flat shading anyway.

ZbuffeR
02-18-2010, 01:13 PM
zNear = 0 in your above call. This is not good and the doc explicitely states it :
http://www.opengl.org/sdk/docs/man/xhtml/gluPerspective.xml

Try any >0 value, like 0.001 instead.

Rocketman
02-18-2010, 02:20 PM
Solved...Thanks mate!!

Rocketman
02-20-2010, 08:26 AM
Sorry to keep asking questions, but I'm still having problems with gluPerspective. Even at a value of 0.01 when I'm changing the values of gluLookat() I'm getting various bits of my image chopped off. It's fine if I look head on, but to the side it's not correct

if I comment out both glulookat and gluPerspective I get the image looking correct, but zoomed out quite far. The same angle, but zoomed in using glulookat and perspective seems to chop off half my image. I still see a red colour from the ambient lighting, but the shading goes completely

Thanks

edit - it seems as though the light is hitting the wrong side of my surface when using gluPerspective

ZbuffeR
02-20-2010, 02:05 PM
Well you are doing wrong, but to help you more will be difficult without the complete code related to your transformations matrices, for both modelview and projection.

Rocketman
02-20-2010, 04:51 PM
I found my problem, my light source was positioned on the wrong side of my image. Apologies