Hello Guest

Projection, View and Model matrices tutorial broken

  • 3 Replies
  • 5030 Views
Projection, View and Model matrices tutorial broken
« on: August 23, 2013, 06:48:52 »
The last of the modern OpenGL tutorials is slightly broken.
http://www.lwjgl.org/wiki/index.php?title=The_Quad_with_Projection,_View_and_Model_matrices



Issue 1:
import premade.VertexData;  // doesn't exist. BUT also not used, so can just remove.

Issue 2:
Camera pos is initialized to the same location as the model, so you see nothing when you start.
Fix:
Code: [Select]
cameraPos = new Vector3f(0, 0, -1);
Issue 3:
setupShaders is basically broken. Through trial and error I got it working.

Through trial and error, I found that you needed to call glBindAttributeLocation BEFORE glLinkProgram, and glGetUniformLocation has be called after.
Also, there was code that carefully detached and deleted the shaders before doing anything else, which seemed odd.

Fixed code:
Code: [Select]
private void setupShaders() {
// Load the vertex shader
vsId = this.loadShader("assets/shaders/moving/vertex.glsl", GL20.GL_VERTEX_SHADER);
// Load the fragment shader
fsId = this.loadShader("assets/shaders/moving/fragment.glsl", GL20.GL_FRAGMENT_SHADER);

// Create a new shader program that links both shaders
pId = GL20.glCreateProgram();
GL20.glAttachShader(pId, vsId);
GL20.glAttachShader(pId, fsId);

        // NB: glBindAttributeLocation seems to be needed BEFORE glLinkProgram
// Position information will be attribute 0
GL20.glBindAttribLocation(pId, 0, "in_Position");
// Color information will be attribute 1
GL20.glBindAttribLocation(pId, 1, "in_Color");
// Textute information will be attribute 2
GL20.glBindAttribLocation(pId, 2, "in_TextureCoord");

GL20.glLinkProgram(pId);
GL20.glValidateProgram(pId);

// Get matrices uniform locations
// NB: glGetUnifromLocation seems to require at least glLinkProgram to work.
projectionMatrixLocation = GL20.glGetUniformLocation(pId,"projectionMatrix");
viewMatrixLocation = GL20.glGetUniformLocation(pId, "viewMatrix");
modelMatrixLocation = GL20.glGetUniformLocation(pId, "modelMatrix");

this.exitOnGLError("setupShaders");
}

Hope this helps someone.

*

Offline quew8

  • *****
  • 569
  • Because Square Eyes Look More Real
Re: Projection, View and Model matrices tutorial broken
« Reply #1 on: August 23, 2013, 10:18:37 »
Hmmm, lots of people seem to be finding problems with these tutorials. I'll go and make your changes, but for the record requiring glBindAttributeLocation before glLinkProgram (and a few other things as I recall) is a driver specific thing. Nvidia cards specifically I think.

*

Offline quew8

  • *****
  • 569
  • Because Square Eyes Look More Real
Re: Projection, View and Model matrices tutorial broken
« Reply #2 on: August 23, 2013, 10:27:20 »
Changes have been made according to your post. Thankyou.

Re: Projection, View and Model matrices tutorial broken
« Reply #3 on: August 24, 2013, 01:23:46 »
Ta!
I did wonder if it was vendor specific.

For the record, I'm using an AMD M880G with ATI Mobility Radeon HD 4250

OpenGL Version: 3.2.10179 Core Profile Forward-Compatible Context
OpenGL Vendor: ATI Technologies Inc.