0

this might be a silly question, but i am trying to debug why the vertices are not being transformed properly,

vertex shader:

#version 300 es
layout (location = 0) in vec3 position;
layout (location = 1) in vec4 color;
layout (location = 2) in vec3 normal;
layout (location = 3) in vec2 uv;

out vec4 oColor;
out vec3 oNormal;
out vec2 oUV;

uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;


void main()
{
   oColor = color;
   oNormal = normal;
   oUV = uv;
   mat4 mo = mat4(
      1.0,0.0,0.0,1.0,
      0.0,1.0,0.0,0.0,
      0.0,0.0,1.0,0.0,
      0.0,0.0,0.0,1.0
   );
   gl_Position =  mo * vec4(position.x, position.y, position.z, 1.0);
}

fragment shader

#version 300 es
precision mediump float;

out vec4 FragColor;

in vec4 oColor;
in vec3 oNormal;
in vec2 oUV;

void main()
{

   FragColor = oColor;
}

when i use write gl_position = vec4(position, 1.0) the result is this: result without using model matrix

when i write gl_position = mo * vec4(position, 1.0) the result is this:result after using the model matrix

i am guessing this has sonmthing to do with viewport, PS: i am not setting any viewport configuration using glViewport.

the project setup is done using emscripten version 2.0.6 and i am trying to draw onto a html canvas using opengles.

  • You need to transpose the matrix. – Rabbid76 Jun 23 '22 at 09:45
  • it works, now, thank you @Rabbid76, also got a good understanding of row and column major paradigm of matrices from [link](https://stackoverflow.com/questions/17717600/confusion-between-c-and-opengl-matrix-order-row-major-vs-column-major) – vishal kumar Jun 23 '22 at 10:35

0 Answers0