Jump to content
  • Advertisement
delete_this_acc_pls

deleted

This topic is 428 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
1 hour ago, DaniDesu said:

glBufferData(GL_ARRAY_BUFFER, sizeof(coordinates), coordinates, GL_STATIC_DRAW);

At a very quick glance over you code, I suspect this is an issue (there may be more), you appear to be passing in the sizeof( pointer ) - what you need here is the size of the array you are passing in -  so something like sizeof(float)*countVertices
 

If the above doesnt help, maybe just add some error checks to ensure that your shaders are compiling and linking as expected- I know you dont want to add error checks yet, but maybe just start with these

Share this post


Link to post
Share on other sites
7 minutes ago, DaniDesu said:

Thus, I wonder why the glBufferData() function has apparently issues with it, since coordinates is an (passed) array after all...

Just on this, although it appears correct, when you pass an array like this, you are passing a pointer to its first element, if you check the sizeof function, it will say the size of your array is only 4 bytes so when you pass your array using glBufferData, you are saying to pass the 4 bytes. Your coordinates array is 12 floats - which is 12 x 4 bytes = 48 bytes. So you are not sending the whole array

Share this post


Link to post
Share on other sites
15 minutes ago, DaniDesu said:

I tried this, since it has 3 float vertices, which makes 9 * sizeof(float), because each vertex has 3 floats:

Apologies, you are correct, i had said 12x rather then 9x.

Are you getting any warnings in your code, I would expect the returning of the address shown below would cause a warning:

6 hours ago, DaniDesu said:

GLuint & MyShapes::drawTriangle(float coordinates[])

You are returning the address of a local variable, which may also cause an issue, in this case you could just return what the value actually is. Maybe just step through your program and see what you get for your shader ID's VAO etc. when you generate them, and compare them when they are later called, for example with the above mentioned, see if the below is what is expected

6 hours ago, DaniDesu said:

glBindVertexArray(vertexArrayObjectHandle);

 

Share this post


Link to post
Share on other sites
7 minutes ago, DaniDesu said:

Now at least I get a linker error, and the triangle is drawn, but not in red...

Getting closer :) - the reason it is not red, and/or other issues you may see may be due to your error handling. As you mentioned, you are seeing a linker error, but you are not doing anything but outputting the error, and then carrying on, this could be cascading the problem to the next shader, and causing unknown issues.
The easiest way to handle this is to turn your compileShaders method into a boolean method, and return false once an error is detected (after outputting your error somewhere) - this way your program will stop at the stage it fails, rather then going on to do whatever craziness it might do after a section fails.. A shader failure is not something you really need to try to recover from, as if its incorrect its incorrect- you fix it, recompile, and hopefully it will move onto the next shader, and you fix it then and so on..

If you havent already, check out https://learnopengl.com/ Its a great resource for getting you up and going in opengl, and is quite easy to follow, unlike alot of the opengl tutorials out there

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!