Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 08 Apr 2013
Offline Last Active Oct 29 2015 08:38 PM

Posts I've Made

In Topic: Java, AWT Image not Appearing

20 October 2015 - 04:02 PM

Good to know.

I'd just invent my own method name and put the invokeLater in there, not override a component method which may be called from other places. Or actually a cleaner solution would be, just create your own renderer class that does not extend a component, just have it as a member.


I suppose I can try to hide it a bit better. The only real thing I've overwritten is the AWTRenderer's (as a JPanel) paintComponent() method, which I don't see how I could have avoided. The draw method is inherited from a Renderer interface.


The AWTRenderer is really the only thing that needs to know about JFrames and JPanels. The actual drawing should happen like the AWTImage does. I've tried my best to create a layer of Abstraction over everything that's AWT specific. I think the only thing that's not currently are the Assets, which I'm planning on changing over to the Renderer knowing what kind of AssetFactory to create and having the AssetManager pull from the Renderer to get that. 


EDIT: To reiterate, as I'm not sure I was clear, the invokeLater isn't part of a function that's overriding a Component function.


EDIT 2: The reason I extended the JPanel originally was because in order to draw on it, I needed a reference to its Graphics component, which is given in the paint component function.

In Topic: Java, AWT Image not Appearing

20 October 2015 - 03:46 PM

Just try to wrap the redraw call (the one in your main loop) in a runnable and use SwingUtilities?


I'll look into doing this. I sort of see how, but I need to think through how to hide it behind the interfaces I use since it's AWT specific. Will report back.


EDIT: Oh, wait duh. Just changed the draw(GameScreen) method in AWTRenderer to:

	public void draw(GameScreen p_Screen)
		this.m_Screen = p_Screen;
		SwingUtilities.invokeLater( new Runnable() {
			public void run() {

Seems to be working now!

In Topic: Java, AWT Image not Appearing

20 October 2015 - 03:35 PM

Are you calling it yourself? Usually you make some call to inform AWT that some component needs to be repainted and then it automagically calls the components painting.
If you are in some other thread you can use SwingUtilities.invokeLater or invokeAndWait.

Here's the full AWTRenderer class:




Whenever I want to redraw (which is currently done in the main loop, sad.png ) I call the draw(GameScreen) function in AWTRenderer. As the AWTRenderer is a JPanel itself, it tells itself to repaint. 


EDIT: I did a little further investigation that I could think of, and tried have a rectangle on screen that moves around with just a simple move its location every time its drawn. However, it gets drawn the first time, and the screen doesnt seem to refresh. However, print statements there (crappy debugging method, I know sad.png ) and later down the call chain show the function is being called.


EDIT 2: Just remembered that resizing the screen makes it update. This has caused the image to be drawn, and the rectangle moves, but the screen never refreshes on its own.

In Topic: Java, AWT Image not Appearing

20 October 2015 - 02:31 PM

Not sure if thats the problem, but you are aware that you should only call AWT and Swing methods from the AWT thread, right?


Was not aware of this. However, I feel like the draw calls I'm making should be on that thread, as the calls are done when the Render is told to repaint. The draw call is done in the paintComponent method, as seen here:

public void paintComponent(Graphics g_Old)
	this.m_Graphics = g_Old;
	if (this.m_Screen != null)

Edit: I realize the repaint method isn't called within the AWT thread. I'd have to implement the draw loop into that thread, I suppose, to make that happen. For now, that was just happening in the main loop. Could that be the cause?

In Topic: Learning Graphics Development

20 April 2015 - 10:29 PM


I would definitely recommend jumping into the current API's and more specifically OpenGL due to it's cross-platform nature.


I generally don't like it when people give this advice. Yes, OpenGL is cross-platform, but anyone who has any experience with cross-platform (or even cross-vendor!) OpenGL development knows how much of a pain it is to get consistent results across platforms and hardware. I'd choose DirectX over OpenGL any time just to avoid the extension and driver compatibility hell.



I actually ended up going with DIrectX, via SharpDX. I'm not concerned with actual development at this point in time, and this is more of a side project type of thing than an actual career decision.