SWT & OpenGL

Hi All,

Not sure if this is the right place to post this, but I am trying to write a game using SWT and its OpenGL Plugin. I am running into problems when I try to load textures and enable alpha blending. I am loading textures from a PNG file that has an alpha channel defined. The image is loaded by a ImageLoader object into a ImageData object. So far so good. Then when I try to create the texture through the glTexImage2D()
call, an exception is thrown. The following is the exact call:

GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, 4, source[0].width, source[0].height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, source[0].data);

And I get the following error:

=================================================================
An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION occurred at PC=0x69042298
Function=[Unknown.]
Library=(N/A)

NOTE: We are unable to locate the function name symbol for the error
just occurred. Please refer to release documentation for possible
reason and solutions.

Current Java thread:
at org.eclipse.swt.opengl.GL.glTexImage2D(Native Method)
at beje.BejeCanvas.loadTexture(BejeCanvas.java:143)
at beje.BejeCanvas.initTexture(BejeCanvas.java:113)
at beje.BejeCanvas.init(BejeCanvas.java:85)
at beje.BejeCanvas.(BejeCanvas.java:64)
at beje.Main.run(Main.java:41)
at beje.Main.main(Main.java:81)

Dynamic libraries:
0x76AC0000 - 0x76ADD000 C:\WINDOWS\SYSTEM\IMAGEHLP.DLL

Local Time = Mon Jun 23 03:25:11 2003
Elapsed Time = 6

The exception above was detected in native code outside the VM

Java VM: Java HotSpot™ Client VM (1.4.1_03-b02 mixed mode)

An error report file has been saved as hs_err_pid4293977641.log.

Please refer to the file for further information.

=================================================================

I don’t get this error if the 3rd argument of lTexImage2D is changed from 4 to 3, and when GL.GL_RGBA is changed to GL.GL_RGB.

I am wondering if anyone has came across this problem, or have a clue why this is happening. ??? Any help is greatly appreciated! Thanks!

btw, I am using Windows 98.

Thanks,
Ed

Other than ensuring that:

source[0].data.length == (source[0].width * source[0].height * 4 /RGBA/)

I cannot think of anything. Since it works switching from 4 -> 3 I would definitely believe that the array is of the incorrect size.

I don’t remember running into any problems when I used the SWT OpenGL plugin. I will be getting out an JOGL port to SWT shortly. I am working through a mire of goo trying to get communication between myself and the Eclipse and JOGL teams. It’s resolving itself slowly.

Thanks very much !!
The OpenGL SWT community seems rather small…
But I’m really thankful that people haven’t given
up on it.

I was wondering if you have an inside view on SWT
people’s direction right now :

Is there furthure development being done for the
SWT OpenGL plugin? Or is the consensus of the SWT
people to trash it and try to integrate with JOGL??

Anyways, I’m eagerly awaiting your JOGL port to SWT
;D

I have been in touch with the Eclipse people and I do not have a firm commitment on their direction. The word is that they have a lot of work to do and OpenGL is not a committed item for 3.0. This basically means that it will get attention as the individual developers have time.

I have my biz dev team starting to work with the Eclipse project to see how we can move forward in a manner that is mutually beneficial while providing the best OpenGL support for SWT.

My personal opinion is that once our product suite is available (you can get some hints from our site at http://www.realityinteractive.com) then there will be A LOT of people jumping on the SWT bandwagon – so stick with it. Of course this opinion is highly biased :slight_smile:

Thank you sooo much! :slight_smile:
Ya, the array size was incorrect. After fixing that, it doesn’t crash anymore.

Also got my desired blending to work now!

Thank you!
Ed

Glad that I could help. If I may be so bold as to offer a few suggestions that may help you down the road based on the snippet that you sent (and, yes, I know it’s a snippet):

  1. Comment. Comment, comment, comment. The extra 5 minutes that you spend commenting will save 5 hours later. For example, you have a few constants in your expression. When you’re deep in the mix looking for a pesky bug, you’ll question everything that you did. “Why did I choose 4?” will come to mind at first glance. Just add a 2 second comment to help:

    GL.glTexImage2D(GL.GL_TEXTURE_2D, 0 /* mipmap*/, 4 /RGBA/, source[0].width, source[0].height, 0 /border/, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, source[0].data);

  2. Code defensively. JDK 1.4 provided us with assertions. Use them. Taking 5 seconds to add an assertion before the glTextImage2D() call (which leaves the protection of the JVM and ventures into the unknown) would save hours of debugging later. Just remember that assertions are DISABLED by default. Get in the habit of adding assertions as you code. As you code more and more, you’ll get more adept a knowing the common gotcha points (mainly arrays and null pointers) and just add assertions without even thinking.

  3. As somewhat a rule of thumb, if you call into an array more than once, make a local reference. This has less to do with performance than it does with anticipating refactoring and debugging, though accessing array can be expensive. Following along with #2, it’s easier to add the assert statement if you make a local reference. It’s also easier to create a difficult to find bug if you have the same base statement (source[0]) three times as the eye will tend to scan it quickly rather than focus on it.

Just trying to be helpful.