Question

The end goal is to be able to render images of arbitrary sizes in JOGL and do it fast on basic graphic cards.

My initial attempt was to achieve this using textures. However, I ran into problems on some graphics cards, (more precisely, virtual machine graphics cards).

Some images exceed the GL_MAX_TEXTURE_SIZE and if the card does not support textures which are not power of two (gl.isNPOTTextureAvailable())

I then followed several (1, 2) samples which used glDrawPixels to render the image directly.

gl.glBlendFunc (GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
gl.glEnable (GL.GL_BLEND);
gl.glColor3f (0.0f, 0.0f, 0.0f);
gl.glRasterPos2i (10, 300);
gl.glDrawPixels (dukeWidth, dukeHeight,
                 gl.GL_RGBA, gl.GL_UNSIGNED_BYTE,
                 dukeRGBA);

This works fine, except when the raster position moves outside the viewport. When part of the image (bottom left corner) goes outside the viewport, the whole image is not displayed.

[1] https://today.java.net/pub/a/today/2003/09/11/jogl2d.html

[2] http://www.java-tips.org/other-api-tips/jogl/drawing-pixels-and-showing-the-effect-of-gldrawpixels-glcopypixels-and-glpix.htm

I have managed to solve the image disappearing problem by replacing glRasterPos2i with glWindowPos2d but again this lead to another problemn - glWindowPos2d is only supported from openGL 1.4 and my virtual machines only support 1.1.

What is wrong with my approach?

Should I be handing images which are non-power size by padding textures?

Should I split large images into many textures (like a quilt) so that maximum texture size in not exceed? worried about performance in this case.

Tried Mesa3D to ensure obtain a higher openGL version, but cannot make it compile for windows. Any other software renderers recommended? (waiting on Swiftshader support)

Was it helpful?

Solution

I have managed to figure out an answer to my own question.

http://www.opengl.org/wiki/Raster_Position_And_Clipping

How do I draw glBitmap() or glDrawPixels() primitives that have an initial glRasterPos() outside the window's left or bottom edge?

When the raster position is set outside the window, it's often outside the view volume and subsequently marked as invalid. Rendering the glBitmap and glDrawPixels primitives won't occur with an invalid raster position. Because glBitmap/glDrawPixels produce pixels up and to the right of the raster position, it appears impossible to render this type of primitive clipped by the left and/or bottom edges of the window.

However, here's an often-used trick: Set the raster position to a valid value inside the view volume. Then make the following call:

glBitmap (0, 0, 0, 0, xMove, yMove, NULL);

This tells OpenGL to render a no-op bitmap, but move the current raster position by (xMove,yMove). Your application will supply (xMove,yMove) values that place the raster position outside the view volume. Follow this call with the glBitmap() or glDrawPixels() to do the rendering you desire.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top