Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualmikenovemberoscar

Posted 29 August 2013 - 06:07 AM

Hi all,

 

I recently discovered that the latest OpenGL standards have deprecated glTranslatef and a bunch of other immediate-mode functions.

My graphics hardware is not great (it doesn't support VAOs, for instance) but I feel I should learn the correct way of doing things.

 

I read these tutorials: http://www.swiftless.com/opengltuts/opengl4tuts.html and the ones at opengl-tutorial.net.

 

I tried to implement shaders into my code, but I just see some yellow lines...

 

Here's what I'm doing: (my shader loading function is from here):

 

In the initiation procedure:

      glViewport(0, 0, (GLsizei) screenSize.x, (GLsizei) screenSize.y);
      projectionMatrix = glm::perspective( 75.0f, screenSize.x / screenSize.y, clip_near, clip_far);

      int programShaderID = loadShaders("vertexShader.txt","fragmentShader.txt");
      glBindAttribLocation(programShaderID, 0, "in_Position"); // Bind a constant attribute location for positions of vertices
      glUseProgram(programShaderID);

Drawing is done by VBOs only (my hardware doesn't support VAOs AFAIK), in the usual way as far as I can see.

 

Every frame, after drawing:

        int projectionMatrixLocation = glGetUniformLocation(programShaderID, "projectionMatrix"); // Get the location of our projection matrix in the shader  
        int viewMatrixLocation = glGetUniformLocation(programShaderID, "viewMatrix"); // Get the location of our view matrix in the shader  
        int modelMatrixLocation = glGetUniformLocation(programShaderID, "modelMatrix"); // Get the location of our model matrix in the shader

        glUniformMatrix4fv(projectionMatrixLocation, 1, GL_FALSE, &projectionMatrix[0][0]); // Send our projection matrix to the shader  
        glUniformMatrix4fv(viewMatrixLocation, 1, GL_FALSE, &viewMatrix[0][0]); // Send our view matrix to the shader  
        glUniformMatrix4fv(modelMatrixLocation, 1, GL_FALSE, &modelMatrix[0][0]); // Send our model matrix to the shader  

Shaders:

     vertex:

#version 330 core
in vec3 in_Position;

void main(){

    uniform mat4 projectionMatrix;  
    uniform mat4 viewMatrix;  
    uniform mat4 modelMatrix;  

	gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(vertexPosition_modelspace, 1.0);
 }

     fragment:

#version 330 core
out vec3 color;
 
void main(){
    color = vec3(1,0,0);
}

I can see something, but my glm::matrices are not seeming to work (i.e. the translation is NOT happening).

I'm so confused, and most of the tutorials seem to use VAOs which I can't do.

 

Am I doing this right?

Can I use shaders without VAOs?

Am I supposed to pass vertex to a shader, like I did with the matrices?

 

EDIT:

I checked, and it is only the translation which is not happening as far as I can see. Why is this?

 

Thanks very much in advance

 

mikey


#2mikenovemberoscar

Posted 29 August 2013 - 04:29 AM

Hi all,

 

I recently discovered that the latest OpenGL standards have deprecated glTranslatef and a bunch of other immediate-mode functions.

My graphics hardware is not great (it doesn't support VAOs, for instance) but I feel I should learn the correct way of doing things.

 

I read these tutorials: http://www.swiftless.com/opengltuts/opengl4tuts.html and the ones at opengl-tutorial.net.

 

I tried to implement shaders into my code, but I just see some yellow lines...

 

Here's what I'm doing: (my shader loading function is from here):

 

In the initiation procedure:

      glViewport(0, 0, (GLsizei) screenSize.x, (GLsizei) screenSize.y);
      projectionMatrix = glm::perspective( 75.0f, screenSize.x / screenSize.y, clip_near, clip_far);

      int programShaderID = loadShaders("vertexShader.txt","fragmentShader.txt");
      glBindAttribLocation(programShaderID, 0, "in_Position"); // Bind a constant attribute location for positions of vertices
      glUseProgram(programShaderID);

Drawing is done by VBOs only (my hardware doesn't support VAOs AFAIK), in the usual way as far as I can see.

 

Every frame, after drawing:

        int projectionMatrixLocation = glGetUniformLocation(programShaderID, "projectionMatrix"); // Get the location of our projection matrix in the shader  
        int viewMatrixLocation = glGetUniformLocation(programShaderID, "viewMatrix"); // Get the location of our view matrix in the shader  
        int modelMatrixLocation = glGetUniformLocation(programShaderID, "modelMatrix"); // Get the location of our model matrix in the shader

        glUniformMatrix4fv(projectionMatrixLocation, 1, GL_FALSE, &projectionMatrix[0][0]); // Send our projection matrix to the shader  
        glUniformMatrix4fv(viewMatrixLocation, 1, GL_FALSE, &viewMatrix[0][0]); // Send our view matrix to the shader  
        glUniformMatrix4fv(modelMatrixLocation, 1, GL_FALSE, &modelMatrix[0][0]); // Send our model matrix to the shader  

Shaders:

     vertex:

#version 330 core
in vec3 in_Position;

void main(){

    uniform mat4 projectionMatrix;  
    uniform mat4 viewMatrix;  
    uniform mat4 modelMatrix;  

	gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(vertexPosition_modelspace, 1.0);
 }

     fragment:

#version 330 core
out vec3 color;
 
void main(){
    color = vec3(1,0,0);
}

I can see something, but my glm::matrices are not seeming to work (i.e. the translation is NOT happening).

I'm so confused, and most of the tutorials seem to use VAOs which I can't do.

 

Am I doing this right?

Can I use shaders without VAOs?

Am I supposed to pass vertex to a shader, like I did with the matrices?

 

Thanks very much in advance

 

mikey


#1mikenovemberoscar

Posted 29 August 2013 - 04:25 AM

Hi all,

 

I recently discovered that the latest OpenGL standards have deprecated glTranslatef and a bunch of other immediate-mode functions.

My graphics hardware is not great (it doesn't support VAOs, for instance) but I feel I should learn the correct way of doing things.

 

I read these tutorials: http://www.swiftless.com/opengltuts/opengl4tuts.html

 

I tried to implement shaders into my code, but I just see some yellow lines...

 

Here's what I'm doing: (my shader loading function is from here):

 

In the initiation procedure:

      glViewport(0, 0, (GLsizei) screenSize.x, (GLsizei) screenSize.y);
      projectionMatrix = glm::perspective( 75.0f, screenSize.x / screenSize.y, clip_near, clip_far);

      int programShaderID = loadShaders("vertexShader.txt","fragmentShader.txt");
      glBindAttribLocation(programShaderID, 0, "in_Position"); // Bind a constant attribute location for positions of vertices
      glUseProgram(programShaderID);

Every frame:

   int projectionMatrixLocation = glGetUniformLocation(programShaderID, "projectionMatrix"); // Get the location of our projection matrix in the shader  
        int viewMatrixLocation = glGetUniformLocation(programShaderID, "viewMatrix"); // Get the location of our view matrix in the shader  
        int modelMatrixLocation = glGetUniformLocation(programShaderID, "modelMatrix"); // Get the location of our model matrix in the shader

        glUniformMatrix4fv(projectionMatrixLocation, 1, GL_FALSE, &projectionMatrix[0][0]); // Send our projection matrix to the shader  
        glUniformMatrix4fv(viewMatrixLocation, 1, GL_FALSE, &viewMatrix[0][0]); // Send our view matrix to the shader  
        glUniformMatrix4fv(modelMatrixLocation, 1, GL_FALSE, &modelMatrix[0][0]); // Send our model matrix to the shader  

 


PARTNERS