0

I wish to bind a texture on a cube (creating cube using GlutSolidCube and not glvertex) but the whole texture is bound. In the image file I have all textures together (for speed and because the teacher requested) and I only want part of the texture to be bound. How can I do that????

John Demetriou
  • 4,093
  • 6
  • 52
  • 88

2 Answers2

4

Textures are the unit of texture binding. If you want to "cut out" part of a texture, you do so by adjusting the texture coordinates that you use.

Instead of using the full range of 0..1, use smaller values that match the sub-texture's location inside the texture.

unwind
  • 391,730
  • 64
  • 469
  • 606
  • I thing you understood question wrong. I wish to bind a texture on an object that I created using glutSolidCube. The problem is I create a whole table using the same function. I wish different part of the texture to be loaded on this cube and different part on that cube. And since I am not using the glvertex function I cannot use glTexCoord2d(U,V) to load parts of the texture. – John Demetriou Oct 29 '12 at 14:25
  • It can also have a C tag btw. Opengl can be used with C or C++ – John Demetriou Oct 29 '12 at 14:29
  • 1
    @macrian And with Java, Clojure and Smalltalk. That doesn't mean you should add a tag for every single language that's been used in the past 15 years though. He answered your question, adjust the UV coordinates. If you can't do that with glutSolidCube, don't use glutSolidCube. – Cubic Oct 29 '12 at 17:54
  • no, the point of adding C as tag is because C and C++ are similar. Very similar. (and by similar I mean g++ recognizes C only code) and by the way since his answer is not suitable for my question I cannot accept the answer..... I need an answer for my question and not a random way to do it. – John Demetriou Oct 29 '12 at 20:42
1

What you're looking to do is not possible, because glutSolidCube does not generate texture coordinates.

However, you will also note that an answer to that question indicates that you may use the following to have OpenGL generate texture coordinates for you on a call to glutSolidCube:

glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);

Some more information on using OpenGL's automatic texture coordinate generation is available here. However, I would like to note that this seems to come out of the days of immediate-mode OpenGL, which is deprecated. Also, GLUT is no longer maintained, but freeglut is.

To summarize, you're better off using glVertex calls and specifying your own specific texture coordinates, as unwind has suggested. You can try OpenGL's texture coordinate generation, but it might be too strict to handle what you need.

Community
  • 1
  • 1
kevintodisco
  • 5,061
  • 1
  • 22
  • 28
  • now this is an answer, don't know if it will work or if you are right and it completely impossible :P I will try it tomorrow (it's 2 o'clock in the morning right now in my country) and let you know – John Demetriou Oct 29 '12 at 23:18