#Vertex data not rendering/outputting properly, problem with perspective matrix??

18 messages · Page 1 of 1 (latest)

mild parrot
#

I'm currently trying to render a green cube rotating on the spot and I'm having an issue where the cubes vertices are going all over the place. I've opened the program through render doc and everything is perfect except for the VS out section, where the cube is going crazy and every time I run the program the VS output seems to be dramatically different even when I don't change the code. With this in mind I think it's most likely an issue with the way I've written the perspective matrix function. The perspective matrix is in source/math.c.

I've also written all the matrixes using single dimension arrays, so maybe opengl treats them differently to two dimensional arrays, which are what the GLM maths library uses and learn opengl.com uses GLM, so maybe it's something to do with that, but not sure.

I'm a newbie programmer, so it could be something opengl related that I did or didn't do, either way I'm open to suggestions and feel free to ask questions.

source: https://github.com/BobbysAccount/BasicOpenglRenderer/tree/main

GitHub

A basic renderer using the opengl API . Contribute to BobbysAccount/BasicOpenglRenderer development by creating an account on GitHub.

delicate python
#

Tough project choice for a new programmer

#

But yeah you need to make sure your matices have the right memory structure

#

I have a hard time believing that "everything is perfect" since the VS out is the direct consequence of your vertex shader inputs acting on the mesh data so if they're messed up your inputs probably are too

mild parrot
#

The Vs input on render doc displays a perfect cube, which is why I'm ruling out the input being the issue

delicate python
#

That's not what I'm talking about

#

You mentioned matrices

#

you're passing matrices to the shader to transform the vertex stream

#

make sure they are correct

mild parrot
#

float *model = identity4x4;
float *view = identity4x4;
float *projection = identity4x4;
model = rotateX(model, (float)glfwGetTime() * 0.5f);
model = rotateY(model, (float)glfwGetTime() * 1.0f);
view = translate(view, newPos);
projection = perspectiveRH(45.0f, (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);

    unsigned int modelLoc = glGetUniformLocation(shaderProgram, "model");
    unsigned int viewLoc  = glGetUniformLocation(shaderProgram, "view");
    unsigned int projectionLoc  = glGetUniformLocation(shaderProgram, "projection");
    
    glUniformMatrix4fv(modelLoc, 1, GL_FALSE, model);
    glUniformMatrix4fv(viewLoc, 1, GL_FALSE, view);
    glUniformMatrix4fv(projectionLoc, 1, GL_FALSE, projection);
#

...this is the way I'm passing the info and I'm pretty sure it's right?

delicate python
#

Renderdoc will tell you that

mild parrot
#

it seems to be receiving the information I'm sending it, but like I said a messed up looking cube is being spat out lol

delicate python
#

Debug one of the vertices on paper and if your answer disagrees with the VS out do some experiments to test how the matrix/vector multiplication behavior differs from yours

mild parrot
#

…ok, so I've tried loads of different variations of the perspective matrix and I've gotten nowhere, is there anyway you could have a quick look at my code and see if there's anything obvious I've missed please?

delicate python
#

I'm at work but honestly this is the perfect opportunity for you to sort it out yourself since you need to learn the fundamentals to continue anyways

#

Subsequent problems are basically going to be the same thing but harder

#

I appreciate your actually trying for several days before asking again though