Load and display an Image on a specific place

Can anyone provides me an example on how to load an image/texture and display it on the screen with its original image size (no scaling)on a specific position of the screen?

I developed a 2D game some time ago using C++/SDL now I want to port it to OpenGL. What I need is a function like: drawimage(texture, positionX, positionY).

I’m an openGL beginner and I looked at many examples but I was not able to create such a simple function (yet).

hi there im pretty fresh at opengl aswell but look at
for some nice executable tutorials

the code you are looking for is going to look something like this

glTranslatef(px, py, 0);
glBindTexture(GL_TEXTURE_2D, texture1);
    glTexCoord2f(offsetX, offsetY);                         glVertex2f(0.0f,+0.0f);
    glTexCoord2f(offsetX, offsetY + -1.0f/16);              glVertex2f(0.0f,-16.0f);
    glTexCoord2f(offsetX+1.0f/16, offsetY + -1.0f/16);      glVertex2f(16.0f,-16.0f);
    glTexCoord2f(offsetX+1.0f/16, offsetY);                 glVertex2f(16.0f,+0.0f);

this is some code taken from my “game-console” the thought is that by making the projection completly flat and reseting the modelview so that z doesn’t matter and by knowing how big the picture is you can display the image without scaling it. in my case every character was 16x16 pixels big.
the code above is just something close, you’ll have to experiment on your own to make it perfect.

Thanks a lot. I’ll play with your example :slight_smile:
I must read more about opengl, some things are not clear to me yet, but looks very very nice (and fast). A little complicated in the beginning but very powerful.


Last August I posted an OpenGL/GLUT/Windows demo that loads image files and displays them as textures AND as an image (with no scaling). The code is self-contained meaning that you don’t have to link with (and learn) an image loading libary. There is also a Linux version of the demo provided by Marshats at the same URL which uses an image handling library called DevIL (looks pretty useful). The URL is -

OpenGL Image Loading and Display Demo

The demo produces the scene below. Loading the image is the hard part. Displaying it requires two OpenGL calls: 1) glRasterPos to position the image, and 2) glDrawPixels to draw it. The demo loads 3 images - an earth map, a fractal image, and the OpenGL logo. The first 2 are displayed as textures. The OGL logo is displayed as an unscaled image.