Hi
I have just went through the 3d tuts on NeHe, it works fine, but when i run my program, the triangle is oversized, and when i try to resize my window, the triangle resizes with it, can anyone help me?
Here is the code:

Just by cutting your vertex positions in half you can size your triangle down. If its still to large, go to a smaller number (0.3f, 0.1f);

That is just a quick fix tho. Other ways would be to move the camera back(also a tutorial on NeHe's site) and physically moving the triangle back in the view. read up on those. NeHe is a great resource for OpenGL. Hope that helped!

---Brandon

11-13-2006

Tonto

I was confused about this topic for awhile, and did not understand that modeling and viewing transformations are so closely related, and it confused me. The OpenGL Redbook explains this very well.

Code:

The Viewing Transformation

Recall that the viewing transformation is analogous to positioning and aiming a camera.
In this code example, before the viewing transformation can be specified, the current matrix
is set to the identity matrix with glLoadIdentity(). This step is necessary since most of the
transformation commands multiply the current matrix by the specified matrix and then set
the result to be the current matrix. If you don't clear the current matrix by loading it with
the identity matrix, you continue to combine previous transformation matrices with the new
one you supply. In some cases, you do want to perform such combinations, but you also
need to clear the matrix sometimes.

Once the matrix is initialized, the viewing transformation is specified with glTranslatef().
The arguments for this command indicate how the camera should be translated (moved)
in the x, y, and z directions. The arguments used here move the camera 5 units in the
negative z direction. By default, the camera as well as any objects in the scene are originally
situated at the origin; also, the camera initially points down the negative z-axis. Thus, the
particular viewing transformation used here has the effect of pulling the camera away from
where the cube is, but it leaves the camera pointing at the object. If the camera needed
to be pointed in another direction, you could have used the glRotatef() command to
change its orientation. Viewing transformations are discussed in detail in "Viewing and
Modeling Transformations."

The Modeling Transformation

You use the modeling transformation to position and orient the model. For example, you
can rotate, translate, or scale the model - or perform some combination of these operations.
Rotating and translating are performed using the commands already mentioned - glRotatef()
and glTranslatef(). In this example, however, the modeling transformation is invoked with
glScalef(). The arguments for this command specify how scaling should occur along the three
axes. If all the arguments are 1.0, this command has no effect; in Example 3-1 , the cube is
drawn twice as large in the y direction. Thus, if one corner of the cube had originally been at
(3.0, 3.0, 3.0), that corner would wind up being drawn at (3.0, 6.0, 3.0). The effect of this
modeling transformation is to transform the cube so that it isn't a cube but a rectangular box.

Note that instead of pulling the camera back away from the cube (with a viewing
transformation) so that it could be viewed, you could have moved the cube away from the
camera (with a modeling transformation). This duality in the nature of viewing and modeling
transformations is why you need to think about the effect of both types of transformations
simultaneously. It doesn't make sense to try to separate the effects, but sometimes it's
easier to think about them one way rather than the other. This is also why modeling and
viewing transformations are combined into the modelview matrix before the transformations
are applied. "Viewing and Modeling Transformations," explains in more detail how to think
about modeling and viewing transformations and how to specify them so that you get the
result you want.

So, you could either physically reduce the size of all the things in your world, or move your viewing point back some as you resize the window I guess. Either way, you could make this problem very easy and very complicated for yourself. You would have fun reading the entire chapter 3 of the redbook http://fly.cc.fer.hr/~unreal/theredbook/chapter03.html You could merely move the viewing point back or you could also change the viewing volume and field of view with some wierd calculations that you decide. That chapter discusses it.

11-13-2006

VirtualAce

The triangle will resize with it if you are using an FOV projection matrix. Hence the aspect ratio being related to height and width of the screen/window. Thus when any of those change, so does the aspect ratio which may affect X, Y, or both.

11-14-2006

ElastoManiac

As i remember the tutorial, the triangle should resize itself along with the window. But you can fix that in later tutorials.
Anyway i highly recommend to use the Red Book. It's better than NeHe ( to me ), although NeHe is pretty good too, but it doesn't explain OpenGL theory, just implementation.

11-14-2006

newtocpp

If you read tutorial 1 again it shows you how to fix it, you left out some of the resizing code in that tutorial. His tutorials are cumulative.