In my CS 550 classes (Computer Graphics; it was a graduate-level class that was open to undergraduates), we did a lot of work with OpenGL and textures. Also, in CS 435, "Multimedia Information Systems," we did some work with OpenGL for displaying images. What I did for a testing environment was pull the code from a 435 project (I belive it was an implementation of image blur) and modified it a bit to display an image stored in an object. This object is an instance of a class Iris, which will be responsible for reading in the image and manipulating it to extract the necessary information. The image is accessible via a public function, and glDrawPixels() is used in the Display() function to draw the image onscreen.
The following is my main.cpp; it compiles with g++ on Ubuntu linux with the following command:
$ g++ -lGL -lGLU -lglut -lX11 main.cpp
I'm not 100% sure if all of these arguments are required for an OpenGL program, but this sequence has served me well in development. I also often add the -ggdb switch so I can run the program through the gdb debugger, which is a lifesaver when it comes to segfaults.
#include <stdlib.h>
#include <GL/glut.h>
#include <GL/glu.h>
void Display();
void Update();
void Mouse(int, int, int, int);
void MouseMove(int, int);
void Keyboard(unsigned char, int, int);
void Special(int, int, int);
void SpecialKey(int, int, int);
void Reshape(int, int);
void Context(int);
#include "iris.h"
Iris* iris;
// World Window Size
int ww_height=600, ww_width=800,
// (Physical) Window Size (aka Viewport)
w_height=600, w_width=800;
void init() {
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(ww_width, ww_height);
glutInitWindowPosition(0,0);
glutCreateWindow("Iris Parse");
glutDisplayFunc(Display);
glutIdleFunc(Update);
glutMouseFunc(Mouse);
glutMotionFunc(MouseMove);
glutKeyboardFunc(Keyboard);
glutSpecialFunc(SpecialKey);
glutReshapeFunc(Reshape);
glClearColor(0.0, 0.0, 0.0, 0.0);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glPolygonMode(GL_FRONT, GL_FILL);
glPolygonMode(GL_BACK, GL_LINE);
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
init();
if (argc>=2)
iris = new Iris(argv[1]);
else
iris = new Iris("eye_color.ppm");
iris->process();
ww_height=w_height=iris->height();
ww_width=w_width=iris->width();
glutMainLoop();
return 0;
}
void Update() {glutPostRedisplay();}
int x=-1, y=-1;
void Display() {
glClear(GL_COLOR_BUFFER_BIT);
glRasterPos2i(x, y);
glDrawPixels(iris->width(), iris->height(), GL_RGB, GL_UNSIGNED_BYTE, iris->data());
glFlush();
glutSwapBuffers();
}
void Mouse(int button, int state, int x, int y) {}
void MouseMove(int x, int y) {y=w_height-y;}
void Keyboard(unsigned char key, int x, int y) {}
void SpecialKey(int key, int xx, int yy) {
if (key == GLUT_KEY_LEFT) x += 1;
else if (key == GLUT_KEY_RIGHT) x -= 1;
else if (key == GLUT_KEY_UP) y += 1;
else if (key == GLUT_KEY_DOWN) y -= 1;
}
void Reshape(int w, int h) {
ww_height=w_height=h;
ww_width=w_width=w;
}