newbie: read and display bitmap

hey guys im a complete newbie in using jogl and im pretty lost… :-\

all i want to do is to read a bitmap file from my hard drive and display it on screen. I have all the initialization stuff up and running and i can get text printed on screen but i cant seem to find the correct method to read and display the image.

from what ive been reading the best method to use is glDrawPixels (pls correct me if im wrong). if so, how do i read the file from the hard drive into a format appropriate to use in this function and what “format” and “type” do i use as arguments to the glDrawPixels?

i’d really appreciate any help i can get…

cheers

Take a look at demos.texture.TestTexture in the jogl-demos workspace. It should give you a head start.

Two possibilities leap to mind for me:

  1. Instead of glDrawPixels, use the TextureIO and Texture classes that are in the com.sun.opengl.util.texture package. Then enable and bind the texture and draw a square with the appropriate texture coordinates:
glBegin( GL_QUADS );
glTexCoord2d(0.0,0.0); glVertex2d(0.0,0.0);
glTexCoord2d(1.0,0.0); glVertex2d(1.0,0.0);
glTexCoord2d(1.0,1.0); glVertex2d(1.0,1.0);
glTexCoord2d(0.0,1.0); glVertex2d(0.0,1.0);
glEnd();

The use of the texture classes is fairly straightforward from the javadocs (and a bunch of the demos use them, as well). This is convinient in JOGL because those texture classes encapsulate all the hard work.

  1. using glDrawPixels, use the javax.imageio.ImageIO.read(file) method to read the file, and pull the pixel data out of the resulting BufferedImage and store it in a java.nio.floatBuffer . You should be able to pass that into glDrawPixels… except, I think (although I’m not sure how consistent this is on various machines), bmp data is stored as BGR instead of the usual RGB, so your format will probably be GL_BGR (although it might be GL_RGB).