Computer Graphics
Frequently Asked Questions
Programming
Graphics
Textures
Miscellaneous
Programming
-
Where can I find an overview of OpenGL/JOGL functions?
Right here.
-
How can I add my own files to the Framework?
To add a file to a project, add the files to the src/ directory in directory of the project. Go to
Eclipse and select the project, press F5 to refresh.
-
I don't want to use Eclipse, can I use my own favorite tool?
We do not care how you create your programs. However, if you decide not to use Eclipse, you're on your own. We do not
provide frameworks for other IDEs and do not provide any help creating those (although we will still answer questions
about problems you
might have with your project, of course). Also, note that you are required to submit an Eclipse project that compiles a
working program. This means that whichever tools or platforms you use, in the end you'll need to put your work back
into Eclipse and test it on VU PCs.
Graphics
-
Why do some parts of my scene appear 'sliced'?
|
When some parts of your scene look like the wings of the F16 shown on the right, you have run into the the depth buffer
resolution problem.
Remember that the z-buffer algorithm determines which polygons are shown in front of others. The resolution of this
ordering is finite; once two polygons fall in the same z-buffer depth, the algorithm cannot distinguish them anymore
and renders them in 'random' order.
Even worse, the resolution of the depth buffer is higher close to the 'near' plane of your viewing volume.
The rationale is that it is more important
to sort the objects close to the viewer correctly than objects far away. However, if you have chosen the near plane to be
very close to the camera, you lose a lot of high resolution close by and get only a very coarse resolution in the
space your objects are actually located in.
The available depth buffer resolution depends on your videocard. Unfortunately, the videocards in the VU PCs do not
have a very high depth buffer resolution.
|
Example of a correctly loaded F16, but with a depth-buffer resolution problem. Parts of the wings
fall in the same depth and are shown in 'random' order
|
Morale: do not place the near plane too close; if the depth buffer resolution becomes a problem, tweak the near plane in such
a way your scene is not unnessesarily clipped and the objects in it look nice. Changing far plane values has less effect, but can
help in certain situations.
More detailed info can be found at OpenGL.org.
-
When I add lighting I do not see colors anymore
When lighting is enabled, OpenGL does not use the values set with glColor(),
but only looks at the material properties set with glMaterial().
Instead of using glMaterial(), you can map some of the material
parameters to the glColor(...) value. To do this, first call glColorMaterial() to
specify which faces and material properties should be tracked (otherwise
the defaults are used.
Second, call glEnable(GL_COLOR_MATERIAL).
From that moment on, all calls to glColor() will also set the specified material
properties. Note that if you choose to map glColor(...) calls to (for example)
GL_DIFFUSE, other properties, like diffuse and ambient, will not be set. If you want to
use non-default settings for these, you'll still need to use glMaterial(...).
-
My lighting looks weird, what can I do?
Debugging lighting is hard, especially if you're new to OpenGL. Here are a few questions to ask yourself
if you find you're lighting just doesn't look quite right:
-
Did you read the previous FAQ-entry?
-
Are your normals correct? This is one of the most common mistakes. Normals should point in the
proper direction, they should be mapped to the right vertex (a common mistake is to put the
glNormal call after the glVertex(...) call it should apply to) and
they should be normalized. Normalized vectors have a length of 1.0. However, even if you define normals
having lengths of 1.0 there can still be problems if you use them with scaling. Under scaling the
length of the vectors will change and the lighting will be affected. To solve this problem, always use
glEnable(GL_NORMALIZE) when using glScale on lit models. For a more detailed description
on the subject of GL_NORMALIZE read the section "Improperly Scaling Normals for Lighting"
on the common OpenGL
pitfalls page.
-
Do my materials and lights have decent values? To know what 'decent' values are, we need to know
how lighting is calculated. The exact lighting equation, used by OpenGL
to calculate the color of each vertex in the scene, can be found in the
Red Book.
A slightly simpler version of it (leaving out some spotlight- and ambient lightmodel stuff)
looks like this:
vertex color =
emissionmaterial +
ambientlight * ambientmaterial +
sum over all the lights 0 to N - 1:
max( l * n , 0 ) * diffuselight * diffusematerial +
max( s * n , 0 ) * shininess * specularlight * specularmaterial
with
N = the number of lights in the scene
l = (lx, ly, lz), the unit vector that points from the vertex to the light position
n = (nx, ny, nz), the unit normal vector at the vertex
s = (sx, sy, sz), the normalized sum of the vector from the vertex to the lightposition and the vertex to the
viewpoint
The simple guidelines you can learn from this are:
-
The
ambient component does not depend on light position or normals, so it will make the color of an object
the same no matter how the object/light/camera is positioned. A light (and/or all materials) should typically
have low values for this, because it doesn't create any illusion of light. It used to give unlit sides of
object some small amount of color to be able to still separate them from a black background.
-
The
emmision does not depend on anything at all. It simply added to the color of the object. You should
avoid this property alltogether, unless you really want a fixed color component.
-
Be careful with large values; the final color is a sum of its parts, and a color value larger
than 1 will be clamped to 1. This means that, for example, when both
ambientlight
and ambientmaterial are set to (1, 1, 1) everything will be white, no matter what
the other material properties are. Some hints on choosing the colors can be found on this
page.
-
Is my light where I want it to be? Remember that
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
is affected by the matrix stack just like glVertex(...). This means that to properly place it in
the scene, you will call glLightfv(...) after setting up the projection and camera, but
before you transform and draw the objects it is supposed to illuminate.
-
Is my texture mode correct? If textures are attached and use GL_REPLACE as texture combine mode,
the color of the texture will overwrite the color of the object, including its lighting. To use
lighting and textures at the same time use another texture combine mode than GL_REPLACE or
GL_DECAL. GL_MODULATE is often a good choice, as it performs component wise
multiplication of object color with texture color.
If your object should not have a texture attached (like the F-16), make sure GL_TEXTURE_2D is
disabled. If not, the texture of a previous object will apply to this object as well!
If none of these questions led to the solution to your problem, you can always email the graphics account to
ask what's wrong.
-
The dino and pony models are ugly, can I use my own?
They are quite ugly indeed. If you think you are capable of making better models in the .sgf format or
capable of writing a loader for a "real" 3D-object format (like .obj, or .3ds), you can use other models.
Just remember that at least one of your models needs to have separately moving parts (such as the arms and
legs of the pony/dino models) and must be textured. In other words: rules 1 through 4 for the final project
should be applicable to at least one model in your scene. If you adhere to these rules, using nicer models
will very likely have a positive effect on your grade, so it may be worth the extra work.
Also, we are happy to accept submissions of nice, home-made models for addition into next years project
framework.
Textures
-
How can I create my own textures?
- Find or create a nice picture (can be any format)
- Make sure the width and height are powers of 2 (for example 128 x 128 or 64 x 256 pixels).
Available tools to accomplish this are:
- Adobe Photoshop (in Windows)
- the GIMP (in Unix)
mogrify -geometry <width>x<height> <file(s)> (in Unix)
- Convert it to an JPEG or PNG image. You can use the Unix tool
convert to do this.
Example:
convert foobar.bmp foobar.jpg
creates a file foobar.bmp from your foobar.tga image.
Miscellaneous
-
The book is not correct!?
Yes, the book (Angel's book, 6th edition) is not perfect.
The author has published some
errata on his website.
-
The answer to my question isn't in this list or on this website. Where can I find more information?
Mail your question to Ben or Maarten {ben,maarten}@cs.vu.nl
|