Loading multiple images

Hi everyone im very new to this and would like some help. All the OpenGL must be done in standard library for it to run on my machine.
So far ive got my programme to open a window, now i need it to open multiple images from disk within that window.Could someone show me the code to do this? Below is what ive got so far…

#include <GL/glut.h> // Include the GLUT header file
#include <GL/gl.h>

#include <GL/glu.h>

#include <stdio.h>

void display (void) {
glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // Clear the background of our window to white
glClear(GL_COLOR_BUFFER_BIT); //Clear the colour buffer (more buffers later on)
glLoadIdentity(); // Load the Identity Matrix to reset our drawing locations

glFlush(); // Flush the OpenGL buffers to the window
}
int main (int argc, char **argv) {
glutInit(&argc, argv); // Initialize GLUT
glutInitDisplayMode (GLUT_SINGLE); // Set up a basic display buffer (only single buffered for now)
glutInitWindowSize (1500, 800); // Set the width and height of the window
glutInitWindowPosition (100, 100); // Set the position of the window
glutCreateWindow (“Image viwer”); // Set the title for the window

glutDisplayFunc(display); // Tell GLUT to use the method “display” for rendering

glutMainLoop(); // Enter GLUT’s main loop
}

From here i want to be able to move the images around and zoom in on them and stuff. But this isnt important yet.

Thank you very much in advance, Tom

Perhaps you should look into a tutorial for this kind of thing.
Like this one http://nehe.gamedev.net/tutorial/lessons_06__10/17010/

Thankyou very much for the link, however i dont want to map the images onto a shape i simply want the images to be there on a canvas. How do i go about this?

Thanks, Tom

You don’t.

You cannot draw an image in OpenGL. You can only draw objects, and you can use texture mapping to map a texture (for your purposes: image) onto that object.

Now, you can draw a flat rectangle or square, the exact size in pixels of the image you want to draw, in the exact place that you want to draw the image. And then you just map the image onto that object, and you will have drawn your image.

This is great, im starting to understand now. So once this is done is there a way to zoom in and out of the images ?

You draw the object bigger and smaller.

Awsome thanks. So now ive managed to create an object and drag it around my window. If i was to create multiple objects in there a way to select a specific object to drag?

OpenGL is a rendering system. It draws stuff. That’s what it does.

It doesn’t know what an “object” is. It has no idea what the mouse is. It doesn’t know what is selected, and it has no concept of dragging.

It draws stuff.

So then what is this if its not click and drag?..

void mouse(int mouse, int state, int x, int y){
switch(mouse){
case GLUT_LEFT_BUTTON:
if(state == GLUT_DOWN){
cout << "x = "<< x << " y= " << y << endl;
a = x/1.0;
b = 300.0 - (y/1.0);

            glutPostRedisplay();
        }
    break;

}
switch(mouse){
    case GLUT_LEFT_BUTTON:
        if(state == GLUT_UP){
            cout &lt;&lt; "x = "&lt;&lt; x &lt;&lt; " y=  " &lt;&lt; y &lt;&lt; endl;
            a = x/1.0;
            b = 300.0 - (y/1.0);

            glutPostRedisplay();
        }
    break;

}

}

void drag(int x, int y){
a = x/1.0;
b = 300.0 - (y/1.0);
glutPostRedisplay();

That is exactly what it looks like: a function (that you didn’t bother to properly format with [ code ] tags) that modifies some global variables and calls glutPostRedisplay. There is no OpenGL happening there at all.

GLUT is not OpenGL.

As you may have understood, OpenGL have no support for this, which means you have to do it all by yourself. First step would be a selection mechanism. You can use a library, like glut, to find the mouse position. You then have to translate this position into an object. There are several ways to do that, generally divided into two main categories. Either you do the calculation manually, transforming your objects and screen position into the same coordinate system, to be able to compare.

Or you use OpenGL indirectly. In legacy OpenGL, there is a way to render and ask what fragment was at a given screen position. One of the usual ways, otherwise, is to draw the objects in unique colours, and then read out the colour at the screen position where the mouse is. That will then give you the identity of the object. Do this in the back buffer, so the user do not see the funny colours.

After you have identified the object that the user selected, use the continuously updated mouse position as input to update the object. It is usually a good practice to change the way the selected object is drawn, to give visual feedback to the user what object was selected.

As you may have understood, OpenGL have no support for this, which means you have to do it all by yourself. First step would be a selection mechanism. You can use a library, like glut, to find the mouse position. You then have to translate this position into an object. There are several ways to do that, generally divided into two main categories. Either you do the calculation manually, transforming your objects and screen position into the same coordinate system, to be able to compare.

Or you use OpenGL indirectly. In legacy OpenGL, there is a way to render and ask what fragment was at a given screen position. One of the usual ways, otherwise, is to draw the objects in unique colours, and then read out the colour at the screen position where the mouse is. That will then give you the identity of the object. Do this in the back buffer, so the user do not see the funny colours.

After you have identified the object that the user selected, use the continuously updated mouse position as input to update the object. It is usually a good practice to change the way the selected object is drawn, to give visual feedback to the user what object was selected. [/QUOTE]

Great thanks for the information! What im basically trying to do is connect a touch screen decvice over a network to remotely control objects on the screen using OpenGL. The user will need to select the different object and zoom in and out of them.

Tom