Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's the difference between image and texture in OpenGL

Tags:

opengl

I just start to learn the OpenGL. I was confused by the Image and texture.

  • Is image only used to shade a 2D scene. And using vertexes and texture to shade the scene in 3D scene? (I mean in the operation order of OpenGL Programming Guide book. First we have vertex data and image data. We can use the image data as the texture or not. When not use as the texture. It's only can be use a background of the scene right. right?)
  • Is texture operation faster than image operation.
like image 536
Samuel Avatar asked Dec 17 '12 06:12

Samuel


1 Answers

In terms of OpenGL an image is an array of pixel data in RAM. You can for instance load a smiley.tga in RAM using standard C functions, that would be an image. A texture is when the imagedata is loaded in video memory by OpenGL. This can be done like this:

GLuint *texID;
glGenTextures(1, (GLuint*)&texID);
glBindTexture(GL_TEXTURE_2D, texID);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, imagedata);

After the image has been loaded into video memory, the original imagedata in RAM can be free()ed. The texture can now be used by OpenGL.

like image 76
Kevin Avatar answered Sep 20 '22 21:09

Kevin