Image Background

Hello!

I’m new to JOGL and OpenGL and am attempting to make a spotlight demo. I need to import a image (jpg or png) to make as a background and then there will be a spotlight that shines on that image. I’ve done some tutorials, but am having difficulty here.

Can anyone give me some pointers to how to import an image and draw it on the screen? What’s the best way to get a spotlight effect?

Thanks for any help and I appreciate all helpful feedback.

Cheers!
Justin

Importing an image as a background in JOGL I think can be done in one of two ways:

  1. The an OpenGL way would be to import the image as a texture and then apply this texture to a couple of triangles in the shape of a square and orient this square as desired…possibly using a billboard effect so that the image is always facing you.

  2. With JOGL you have a GLCanvas or GLJPanel…with the GLJPanel you can place the GLJPanel over another JPanel which would hold your image as the background. The demos have an example that might help: JGears. It doesn’t load a image as the background but I believe it has the ability to turn the background on/off (either JGears or some other demo has this, I’ve seen it).

The demo page (first link below) has some interesting pictures that might be of interest since they include images as backgrounds: Vertex Program Refract, Water (Procedural Texture Physics), Hardware Shadow Mapping

Now, as to the spotlight, I can’t help much there…I would look at some of the demos here (ie the jogl demo sources) or the demos on the java.net site https://jogl-demos.dev.java.net/...specifically the NEHE demos ported to JOGL: http://pepijn.fab4.be/software/nehe-java-ports/

There are a couple of ways of doing a spotlight. If you’re not interested in actual lighting, you could create a second texture that is a white circle (with a transparent background) and use multitexturing to increase the brightness of the original background image.

Or you could use an actual opengl light set to be a spotlight, but for this to work correctly, you’d need to tesselate your background square a lot to get the lighting detail necessary to convey the spotlight.

Or, if you’re comfortable enough with glsl shaders, you could create a per-pixel shader that emulates a spotlight. This would solve the tesselation problem in the second option.

IMO, the 2nd is easiest to start with since the details of textures can be a little complicated (although they’re worth knowing), also the glsl shaders a more advanced technique, so if you’re just getting used opengl, the 2nd would provide a good introduction to the basics.

Thank you both for responding. I am very new to JOGL and OpenGL, so I’m going to have to try it out.

Cheers!
Justin