user2099155
user2099155

Reputation: 25

How to load an png image in openGL and move it by using the mouse?

How can I load an image in openGL? How can I transfer the image data to the data that openGL can understand?

Upvotes: 1

Views: 1295

Answers (2)

Bartek Banachewicz
Bartek Banachewicz

Reputation: 39370

I'll break it into steps:

  1. Read the file contents into memory
  2. Decode the file to raw format required (RGB or RGBA)
  3. Create OpenGL texture object and give the raw image data to OpenGL
  4. Construct OpenGL primitive with appropriate texture coordinates and vertices positions.
  5. Bind the texture to appropriate texture unit and use a sampler object to use the texture data to produce final color.

6. Profit!

Step 1, 2 and 3 can be easily changed to simple SOIL_load_texture call, if you want to use SOIL image library.

Upvotes: 3

Bernd Elkemann
Bernd Elkemann

Reputation: 23550

First you have to decode the image into an RGBA-array. See here:

https://en.wikipedia.org/wiki/libpng

Then you have to map it to an OpenGL-texture and display:

http://nehe.gamedev.net/tutorial/texture_mapping/12038/

Upvotes: 1

Related Questions