dei.andrei98
dei.andrei98

Reputation: 174

OpenGL Texture binding to object

I started learning OpenGL some days ago and I have some difficulties in understanding a thing. I followed this tutorial: https://www.youtube.com/playlist?list=PLEETnX-uPtBXT9T-hD0Bj31DSnwio-ywh until the fifth part and it works perfectly but when I tried to make another separate triangle and another texture for it, the two triangles had the same texture. I don't understand how to bind a texture to an object, this program binds a texture for every object in the scene or maybe I didn't understand how to do it properly. Here is my source: https://github.com/deiandrei/blackunity_opengl_alpha Have a good day!

Upvotes: 0

Views: 85

Answers (1)

datenwolf
datenwolf

Reputation: 162327

What are these "objects" you're talking about? OpenGL doesn't know what a "object" is. OpenGL just knows points, lines and triangles and all it bothers is drawing one after another with the state currently enabled. Once something has been drawn, OpenGL already forgot about it.

So the typical OpenGL program drawing structure roughly looks like this:

glBindTexture(GL_TEXTURE_2D, texture_A);
draw_triangles(); /* the triangles are drawn using texture_A */
draw_lines(); /* the lines are drawn using texture_A */

glBindTexture(GL_TEXTURE_2D, texture_B);
draw_some_other_triangles(); /* the other triangles are drawn using texture_B */

Upvotes: 3

Related Questions