Talk:Tutorial3: Rendering 3D Objects (C /SDL)

From OpenGL Wiki
Jump to: navigation, search

Has any one managed to successfully compile/link this code under windows. I tried getting this to run using SDL 1.3 and GLEW 1.53 on the VC++ 2008 compiler it seemingly compiles fine however all that I manage to see is a white background in the spawned window.

Solved my issue with Tutorial3

After some debugging I narrowed down the issue to an issue with the fragment shader. I believe the issue was caused by the shader compiler supplied by the driver was being strict, possibly because of the original use of the gl_FragColor which is now depreciated.

Changes I made to fix the issue for my uses.

File: tutorial3.frag

#version 150

in  vec3 ex_Color;

out vec4 fragColor;

void main(void)


        fragColor = vec4(ex_Color, 1.0);


Matrix Multiplication Order Question

I've been trying to catch up on OpenGL3+ and have a little trouble understanding the matrix multiplication order for creating the modelviewmatrix. In many vertex shaders i've seen something like

vertex_out = projection * modelview * vertex_in

which (I think) could also be written as

vertex_out = projection * view * model * vertex_in

In this tutorial you multiply the modelview matrix with the projection matrix

multiply4x4(modelmatrix, projectionmatrix);

and in the end use the resulting matrix in the shader. To me this looks like

vertex_out = modelmatrix * projectionmatrix * vertex_in

Could someone please clearify this for me?

Yes, you're right. The vertex data usually is in an abstract model space (e.g. from the modelling tool) and is moved into a common world space by the model matrix. Then it is moved into eye/camera space by the view matrix. These two steps are often combined in the modelviewmatrix. Now it's moved from a 3d world into a normalized space ( x,y and z have to be in range [-1;1] to be visible later ) by the projection matrix. So it's
Position = Projection*View*Model*Vertex
MasterOfGhosts 07:19, 29 August 2010 (UTC)