View Full Version : rendering problems
02-17-2010, 02:53 PM
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.
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?
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 :(
Could anyone suggest if this is a lighting problem? i.e. my normals are wrong, or are my vertex/polygons likely to be wrong
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.
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:
Is it right that I have one normal for three vertex3f() calls?
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.
02-18-2010, 09:57 AM
When I change GL_POLYGON to GL_TRIANGLES, I get this.
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.
02-18-2010, 01:13 PM
zNear = 0 in your above call. This is not good and the doc explicitely states it :
Try any >0 value, like 0.001 instead.
02-18-2010, 02:20 PM
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
edit - it seems as though the light is hitting the wrong side of my surface when using gluPerspective
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.
02-20-2010, 04:51 PM
I found my problem, my light source was positioned on the wrong side of my image. Apologies
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.