Results 1 to 4 of 4

Thread: Load and display an Image on a specific place

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2009

    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).

  2. #2
    Member Newbie
    Join Date
    Jun 2009

    Re: Load and display an Image on a specific place

    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
    Code :
    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.

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2009

    Re: Load and display an Image on a specific place

    Thanks a lot. I'll play with your example
    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.


  4. #4
    Senior Member Regular Contributor
    Join Date
    Mar 2003
    Los Angeles

    Re: Load and display an Image on a specific place

    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.

    Am I doing your homework for you?

Similar Threads

  1. Replies: 1
    Last Post: 05-07-2017, 03:36 AM
  2. how to load and display png image
    By abhishek in forum EGL
    Replies: 0
    Last Post: 06-04-2012, 03:13 AM
  3. Replies: 10
    Last Post: 05-03-2012, 05:32 AM
  4. Replies: 2
    Last Post: 11-23-2011, 04:30 AM
  5. OpenGl, load and display 2D image example?
    By GanMatt in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 07-01-2010, 05:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean