openGL texture question.

Hello, a noob over here :slight_smile:

I have two questions regarding openGL, I just started learning it and now I’m working with textures, but I’m facing somewhat of difficulties in terms of understanding, so here are my two questions:

1- How do you determine the coordinates of the texture? I have already made a small animation of two boxes that use textures, but that code was copied from online, now I understand how the objects like boxes and such work in terms of coordinates, but I would like to understand how the texture works rather than just copy and apply, also I need to understand the S and T parameters, can someone please be kind enough to explain how the texture coordinates work?

2- As I already mentioned, I had boxes loaded with textures, but I need to apply a texture into a background and make it dynamic, for example I’d like to put a space background texture and then have planets, the planets I already have an idea of how to create, but whenever I try to put a background texture it just looks like a background in 2D form and the other objects that I had there (I had two boxes) disappeared, can someone please guide me toward the right direction into building a good dynamic texture background?

I’m using C++ as the programming language, I always thought that openGL was only used with C++ but I was wrong, anyways, thanks in advance :slight_smile:

1- This is a hard question in the general case.
S and T parameters (sometimes called U and V) are the coordinates used to map a point of the geometry to a point of the texture (called texel).
For really complex objects, this is done with 3d modeling software and some solid experience on the subject. The free 3D package Blender has a set of very powerful tools for help this task, see “UV unwrapping” here http://www.blender.org/features-gallery/features/

For programmatic texcoord generation :
Visual representation of the simple cases :
http://www.okino.com/nrs/features/txtrpi2.gif
Some old material on the subject, that will help you get more in depth information :
http://www.opengl.org/resources/code/samples/sig99/advanced99/notes/node80.html
http://www.opengl.org/sdk/docs/man/xhtml/glTexGen.xml
With vertex and pixel shaders you have even more ways to tweak the mapping.

2- A way to do this would be to model a large cube, each face mapped with a star texture. The important things :

  • it should not rotate when the camera rotates
  • it should translate as if attached to the camera
  • you can draw first while disabling depth test, so all other objects will appear in front of it.

You can also try with a large sphere, it does not need a detailed tesselation. But texturing the poles correctly is tricky.

With C/C++ it is somewhat easier to use opengl, but probably any language of your choice will do. Just check that the extensions / GL 2.1 / GL 3 can be easily used.