Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


#Actualic0de

Posted 12 December 2012 - 10:25 PM

I'm updating some Opengl 2 stuff to Opengl 3+ and I'm having some trouble with the absence of the matrix stack. I'm using GLM (opengl mathematics) to do my matrix operations. I wrote a small function to replace each of the opengl transformation functions with their GLM alternative and replaced all calls to those functions with my own. All that works in theory but when I run my program I get a whole bunch of garbage wonky polygons making no sense. Here is my code:

glm::mat4 modelMatrix;
glm::mat4 modelViewMatrix;
glm::mat4 modelViewProjectionMatrix;
glm::mat3 normalMatrix;
glm::mat4 ProjectionMatrix;
glm::mat4 viewMatrix;

ProjectionMatrix = glm::perspective(60.0f, ratio, 0.1f, 4096.0f); //setup projection
viewMatrix = glm::lookAt(glm::vec3(0.0, 0.0, 0.0), glm::vec3(0.0, 0.0, 1.0), glm::vec3(0.0, 1.0, 0.0)); //set view camera at 0,0,0 looking forward into the z-axis
void coLoadIdentity()
{
modelMatrix = glm::mat4(1.0f);
//glLoadIdentity();
}
void coRotatef(float angle, float x, float y, float z)
{
modelMatrix = glm::rotate(modelMatrix, angle, glm::vec3(x, y, z));
//glRotatef(angle, x, y, z);
}
void coTranslatef(float x, float y, float z)
{
modelMatrix = glm::translate(modelMatrix, glm::vec3(x, y, z));
//glTranslatef(x, y, z);
}
inline void reApplyTransform(vec viewer, float yaw, float pitch) //used to apply two operations with one function for simplicity
{
coLoadIdentity();
coRotatef(pitch, 1.0, 0.0, 0.0);
coRotatef(yaw, 0.0, 1.0, 0.0);
coTranslatef(viewer.x, viewer.y, viewer.z);
}
void updateMatrices() //called before something is drawn and after transformations have been applied
{
modelViewMatrix = modelMatrix * viewMatrix;
modelViewProjectionMatrix = modelViewMatrix * ProjectionMatrix;
normalMatrix = glm::inverseTranspose(glm::mat3(modelViewMatrix));
glUniformMatrix4fv(mvmat_loc, 1, false, glm::value_ptr(modelViewMatrix));
glUniformMatrix4fv(mvpmat_loc, 1, false, glm::value_ptr(modelViewProjectionMatrix));
glUniformMatrix3fv(nmat_loc, 1, false, glm::value_ptr(normalMatrix));
}

vertex shader:
void main(void)
{
vnormal = normalize(normalMatrix * normal);
vec3 ntangent = normalize(normalMatrix * tangent.xyz);

vec3 bitangent = cross(vnormal, ntangent) * -tangent.w;

TBN = mat3(ntangent, bitangent, vnormal);

	v = vec3(modelViewMatrix * vec4(position, 1.0));
	VaryingTexCoord0 = vec4(vec3(texCoord, 0), 0);
	gl_Position = modelViewProjectionMatrix * vec4(position, 1.0);
}

anybody spot anything obviously wrong?

#3ic0de

Posted 12 December 2012 - 10:24 PM

I'm updating some Opengl 2 stuff to Opengl 3+ and I'm having some trouble with the absence of the matrix stack. I'm using GLM (opengl mathematics) to do my matrix operations. I wrote a small function to replace each of the opengl transformation functions with their GLM alternative and replaced all calls to those functions with my own. All that works in theory but when I run my program I get a whole bunch of garbage wonky polygons making no sense. Here is my code:

glm::mat4 modelMatrix;
glm::mat4 modelViewMatrix;
glm::mat4 modelViewProjectionMatrix;
glm::mat3 normalMatrix;
glm::mat4 ProjectionMatrix;
glm::mat4 viewMatrix;

ProjectionMatrix = glm::perspective(60.0f, ratio, 0.1f, 4096.0f); //setup projection
viewMatrix = glm::lookAt(glm::vec3(0.0, 0.0, 0.0), glm::vec3(0.0, 0.0, 1.0), glm::vec3(0.0, 1.0, 0.0)); //set view camera at 0,0,0 looking forward into the z-axis
void coLoadIdentity()
{
modelMatrix = glm::mat4(1.0f);
//glLoadIdentity();
}
void coRotatef(float angle, float x, float y, float z)
{
modelMatrix = glm::rotate(modelMatrix, angle, glm::vec3(x, y, z));
//glRotatef(angle, x, y, z);
}
void coTranslatef(float x, float y, float z)
{
modelMatrix = glm::translate(modelMatrix, glm::vec3(x, y, z));
//glTranslatef(x, y, z);
}
inline void reApplyTransform(vec viewer, float yaw, float pitch) //used to apply two operations with one function for simplicity
{
coLoadIdentity();
coRotatef(pitch, 1.0, 0.0, 0.0);
coRotatef(yaw, 0.0, 1.0, 0.0);
coTranslatef(viewer.x, viewer.y, viewer.z);
}
void updateMatrices() //called before something is drawn and after transformations have been applied
{
modelViewMatrix = modelMatrix * viewMatrix;
modelViewProjectionMatrix = modelViewMatrix * ProjectionMatrix;
normalMatrix = glm::inverseTranspose(glm::mat3(modelViewMatrix));
glUniformMatrix4fv(mvmat_loc, 1, false, glm::value_ptr(modelViewMatrix));
glUniformMatrix4fv(mvpmat_loc, 1, false, glm::value_ptr(modelViewProjectionMatrix));
glUniformMatrix3fv(nmat_loc, 1, false, glm::value_ptr(normalMatrix));
}

vertex shader:
void main(void)
{
vnormal = normalize(normalMatrix * normal);
vec3 ntangent = normalize(normalMatrix * tangent.xyz);

vec3 bitangent = cross(vnormal, ntangent) * -tangent.w;

TBN = mat3(ntangent, bitangent, vnormal);

	v = vec3(modelViewMatrix * vec4(position, 1.0));
	VaryingTexCoord0 = vec4(vec3(texCoord, 0), 0);
	gl_Position = modelViewProjectionMatrix * vec4(position, 1.0);
}

anybody spot anything obviously wrong?

#2ic0de

Posted 12 December 2012 - 10:23 PM

I'm updating some Opengl 2 stuff to Opengl 3+ and I'm having some trouble with the absence of the matrix stack. I'm using GLM (opengl mathematics) to do my matrix operations. I wrote a small function to replace each of the opengl transformation functions with their GLM alternative and replaced all calls to those functions with my own. All that works in theory but when I run my program I get a whole bunch of garbage wonky polygons making no sense. Here is my code:

glm::mat4 modelMatrix;
glm::mat4 modelViewMatrix;
glm::mat4 modelViewProjectionMatrix;
glm::mat3 normalMatrix;
glm::mat4 ProjectionMatrix;
glm::mat4 viewMatrix;

ProjectionMatrix = glm::perspective(60.0f, ratio, 0.1f, 4096.0f);
viewMatrix = glm::lookAt(glm::vec3(0.0, 0.0, 0.0), glm::vec3(0.0, 0.0, 1.0), glm::vec3(0.0, 1.0, 0.0));
void coLoadIdentity()
{
modelMatrix = glm::mat4(1.0f);
//glLoadIdentity();
}
void coRotatef(float angle, float x, float y, float z)
{
modelMatrix = glm::rotate(modelMatrix, angle, glm::vec3(x, y, z));
//glRotatef(angle, x, y, z);
}
void coTranslatef(float x, float y, float z)
{
modelMatrix = glm::translate(modelMatrix, glm::vec3(x, y, z));
//glTranslatef(x, y, z);
}
inline void reApplyTransform(vec viewer, float yaw, float pitch) //used to apply two operations with one function for simplicity
{
coLoadIdentity();
coRotatef(pitch, 1.0, 0.0, 0.0);
coRotatef(yaw, 0.0, 1.0, 0.0);
coTranslatef(viewer.x, viewer.y, viewer.z);
}
void updateMatrices() //called before something is drawn and after transformations have been applied
{
modelViewMatrix = modelMatrix * viewMatrix;
modelViewProjectionMatrix = modelViewMatrix * ProjectionMatrix;
normalMatrix = glm::inverseTranspose(glm::mat3(modelViewMatrix));
glUniformMatrix4fv(mvmat_loc, 1, false, glm::value_ptr(modelViewMatrix));
glUniformMatrix4fv(mvpmat_loc, 1, false, glm::value_ptr(modelViewProjectionMatrix));
glUniformMatrix3fv(nmat_loc, 1, false, glm::value_ptr(normalMatrix));
}

vertex shader:
void main(void)
{
vnormal = normalize(normalMatrix * normal);
vec3 ntangent = normalize(normalMatrix * tangent.xyz);

vec3 bitangent = cross(vnormal, ntangent) * -tangent.w;

TBN = mat3(ntangent, bitangent, vnormal);

	v = vec3(modelViewMatrix * vec4(position, 1.0));
	VaryingTexCoord0 = vec4(vec3(texCoord, 0), 0);
	gl_Position = modelViewProjectionMatrix * vec4(position, 1.0);
}

anybody spot anything obviously wrong?

#1ic0de

Posted 12 December 2012 - 10:21 PM

I'm updating some Opengl 2 stuff to Opengl 3+ and I'm having some trouble with the absence of the matrix stack. I'm using GLM (opengl mathematics) to do my matrix operations. I wrote a small function to replace each of the opengl transformation functions with their GLM alternative and replaced all calls to those functions with my own. All that works in theory but when I run my program I get a whole bunch of garbage wonky polygons making no sense. Here is my code:

glm::mat4 modelMatrix;
glm::mat4 modelViewMatrix;
glm::mat4 modelViewProjectionMatrix;
glm::mat3 normalMatrix;
glm::mat4 ProjectionMatrix;
glm::mat4 viewMatrix;

ProjectionMatrix = glm::perspective(60.0f, ratio, 0.1f, 4096.0f);
viewMatrix = glm::lookAt(glm::vec3(0.0, 0.0, 0.0), glm::vec3(0.0, 0.0, 1.0), glm::vec3(0.0, 1.0, 0.0));
void coLoadIdentity()
{
modelMatrix = glm::mat4(1.0f);
//glLoadIdentity();
}
void coRotatef(float angle, float x, float y, float z)
{
modelMatrix = glm::rotate(modelMatrix, angle, glm::vec3(x, y, z));
//glRotatef(angle, x, y, z);
}
void coTranslatef(float x, float y, float z)
{
modelMatrix = glm::translate(modelMatrix, glm::vec3(x, y, z));
//glTranslatef(x, y, z);
}
inline void reApplyTransform(vec viewer, float yaw, float pitch) //used to apply two operations with one function for simplicity
{
coLoadIdentity();
coRotatef(pitch, 1.0, 0.0, 0.0);
coRotatef(yaw, 0.0, 1.0, 0.0);
coTranslatef(viewer.x, viewer.y, viewer.z);
}
void updateMatrices() //called before something is drawn
{
modelViewMatrix = modelMatrix * viewMatrix;
modelViewProjectionMatrix = modelViewMatrix * ProjectionMatrix;
normalMatrix = glm::inverseTranspose(glm::mat3(modelViewMatrix));
glUniformMatrix4fv(mvmat_loc, 1, false, glm::value_ptr(modelViewMatrix));
glUniformMatrix4fv(mvpmat_loc, 1, false, glm::value_ptr(modelViewProjectionMatrix));
glUniformMatrix3fv(nmat_loc, 1, false, glm::value_ptr(normalMatrix));
}

void main(void)
{
vnormal = normalize(normalMatrix * normal);
vec3 ntangent = normalize(normalMatrix * tangent.xyz);

vec3 bitangent = cross(vnormal, ntangent) * -tangent.w;

TBN = mat3(ntangent, bitangent, vnormal);

    v = vec3(modelViewMatrix * vec4(position, 1.0));
    VaryingTexCoord0 = vec4(vec3(texCoord, 0), 0);
    gl_Position = modelViewProjectionMatrix * vec4(position, 1.0);
}

anybody spot anything obviously wrong?

PARTNERS