Active Rendering, flickering

Hello there,

for a school project we require to build some game. I wanted to use active rendering and created a ‘Window’ class for that. The goal would be to pass an instance of it to a ‘Game’ class which would then ‘draw itself onto it’. I am not sure if this is the correct approach though.

Anyway the problem is that my application is flickering, I am not sure but can it be the primary and backbuffer? Anyway here is my code: https://gist.github.com/anonymous/d55b329f77f9f3a75ef1ff93044874e6. On line 87 of Window2.java you will have to pass ‘true’ as second parameter, that will create the flickering. Also if I call setIgnoreRepaint(true) on my frame BEFORE I initialize the canvas, it does not flicker. If then I additionally do the same for the canvas, it flickers again. Also can someone confirm that this works fine too as it is?.. I guess I do not entirely understand how AWT works in detail so I am not sure if paint() is still called… I used to create a JPanel and simply overriden paintComponent :stuck_out_tongue:

Thankyou for your help :slight_smile:

At the risk of being little or no help, may I ask why you chose to go the active rendering route? Java has double buffering automatically set up with display classes such as JPanel. If the assignment was just to make a game, using that would be a lot easier. (And, using the latest Java graphics library, JavaFX, would be easier, still.)

I’m guessing you’re already acquainted with and have read through the Java Tutorials guide on Active Rendering?

Well there are a few reasons for that. The main reason being that I want to learn it and experiment with it. Also since I would create some window class anyway, I wanted to use the advantages of active rendering. I indeed have read through the Java Tutorials and it was quite helpful, yet I can’t find the error…
The reason we do not use JavaFX is because it’s a team made up of 3 people and the decision was made to not use JavaFX. We are all quite new to JavaFX and did not want to use it for this project, perhaps in the future when there is no deadline :stuck_out_tongue:

Well I have adjusted some stuff and added basic key controls to change resolution & fullscreen mode.
Sometimes the flickering still appears and sometimes the application lags horribly. Especially when I activate this NVidia overlay to capture the gameplay… the mouse moves slow (fullscreen exclusive mode).
Also can someone confirm that the other stuff is alright? Like how I switch from fullscreen to windowed and back? After all I dispose the frame everytime and I am not sure if that is the best solution? Also I know that the KeyListener runs on the EDT but I have found out that it would take a lot of work to also fix that?

Here is the updated version: https://gist.github.com/anonymous/a10f54e7062a7b8fbf6da692a27dc34c

Thankyou for the help :slight_smile: