JOGL and Graphics class problem.

:’( Alright so in my game I am drawing menus using the Graphics class and grabbing them with the BufferedImage class then applying them to be textures for planes on my screen.

No big deal they work wonderfully in my Init() method. Cool beans.

Now if “mid-game” I need to alter a menu I would presume I can draw and load another texture to the same object to change it. Good idea in concept, however, it isn’t turning out that easy for me. So for some reason the BufferedImage class is reading from another one of my textures or perhaps my JOGL rendered scene(in a strange way though), and not the image I am trying to create behind the scene of JOGL.

Don’t understand? watch this SMALL audioless video clip of my work in progress…

Someone on Gamedev.net said I need to make my Context Current. Does this mean make the Context current to my Menu class? What does a JOGL context have to do with BufferedImages and Graphics classes? Is there any feasible way to accomplish what I need done? Any advice/tips/ideas would be so incredible right now!

(And yes I’ve been googling for 48 hours)

After watching the youtube video, I can hardly guess whats wrong. It looks like you messed up some texture binding. I doubt it has anything to do with the BufferedImage actually having the contents of your scene.

I’ll look into that, again…

See the texture it is reading from is stored actually in a different class entirely… In an array list.
Hence my confusion. I’ll give it a couple more stabs and if all else fails I might post some code(which might pose a problem seeing as how big this project is)…

Thank you for your response, and your time!

Is it possible that after I over-write the texture with another that GL gets messed up and just pulls the first texture I loaded(universally))? I just discovered no matter what it uses whatever texture I have in my seperate texture class that is located in my texture array at location 0 for display. I cannot find out why.

This is such a damn struggle, and it just doesnt make any sense… If anyone responds then I will post some code otherwise I guess wish me luck.

You’re right it isn’t an interaction with the graphics class at all. I just tested this by saving the created image to my desktop and it looks exactly how it should. Now I guess I just need to figure out why in the hell it is displaying the first texture I loaded in my Main class while the texture each menu object is using, is inside of the menu object class…

EDIT - Even freaking weirder. I changed my display method around a little bit. And instead of displaying the first texture I loaded in place of it’s real texture. it is displaying the first image loaded into the menuObjects(the main menu)… I’m considering changing how I have all of my data stored now, but this still doesn’t make sense why JOGL is picking and choosing which texture to display when it clearly has it’s own texture. …

I really just don’t get it I might abandon JOGL entirely. Logically this makes no sense… We’ll see if I can’t figure something out by tommarrow…

JOGL isn’t picking a texture. As I said, you have probably binding the wrong texture at the wrong time or have messed up your texture names/ids somewhere. Try to reproduce the problem in a minimal testcase and post the source here. Otherwise all we would do is speculating.

I was trying to reconstruct a project on how to demonstrate the error. Honestly it’d take me just as long probably to make this project haha.

Any chance I could just post it in a ZIP file or something, I trust no one on here won’t steal my work without credit.
But would you(cylab) be willing to try to sort through it? I have it in Eclipse right now, I dunno if that matters or not.

Honestly the code is kind of messy, but I can comment the things of concern.

I would be willing to take a look at the code, but don’t expect anything ;p How much lines of code is in there? Send it to

cylab gmx de

Add @ and . as necessary.

It’s got a decent amount of lines. Most of them are trivial though(accessor, mutator methods, loading media lines etc). But I’ll comment the lines and classes involved. No gaurentee’s isn’t a big deal to me right now haha, thanks for offering some help. Expect an e-mail breifly Cylab.

I’m pretty sure it’s just how I am storing my textures, that is messing JOGL up. I know there’s another way to do the whole texture thing but I don’t recall how to do it. I’m gonna look into that. The E-mail will tell you mainly where to look(there are also comments).

The problem was that you tried to create the texture outside of the init() or display() method. This way you had no current context and the texture creation failed. It seems that you tried to work around this by creating a context and making it current (more or less with brute force ;)).

I didn’t really get the cause, but this apparently created a context independent from your rendering context, that didn’t share it’s resources, so your texture ids in the menu creation started by 1 again. When you tried to show that new menu texture, JOGL of course bound the texture with the ID 1, but this was created in the wrong context and the texture with ID 1 in the right context was shown - which was your background texture…

To fix the problem I removed all context handling from your code and instead made sure that all keyboard/mouse-events are processed in the display() callback.