Show Posts
|
|
Pages: [1] 2 3 4
|
|
1
|
Java Game APIs & Engines / OpenGL Development / JOGL Shader Questions
|
on: 2013-03-24 19:00:03
|
|
I'm trying to figure out how to start using GLSL with JOGL to do pixel shading on images drawn to GLAutoDrawable via glDrawPixels.
I'm confused as to how a few things work in GLSL: 1) How can I access the color of the current pixel in the shader call? What is the form of that pixel (RGB, BGR, etc.) so that I can unpack it? 2) Do I just assign gl_FragColor to change the pixel? 3) How do I get coordinates of the current pixel? 4) Does it generally make more sense to perform lighting calculations in the GLSL frag shader or maybe in OpenCL?
I've trying really hard to muddle through learning JOGL by myself, but I'm really stuck on these fundamental problems with GLSL, and I haven't been able to find consistent help through Google.
Any help is appreciated, and I thank you in advance for your time.
|
|
|
|
|
2
|
Game Development / Performance Tuning / Java2D Native Fullscreen and VSync
|
on: 2013-03-20 23:43:04
|
I've recently come across an interesting phenomenon on Windows while creating a display class for 2D rendering. If you use the following code to set a JFrame as the fullscreen window natively: 1 2 3 4
| GraphicsDevice d = GraphicsEnvironment .getLocalGraphicsEnvironment().getDefaultScreenDevice(); if (d.isFullScreenSupported()) { d.setFullScreenWindow(frame); |
at least on my system, it causes the graphics driver to engage VSync on Java's rendering. I know this because when I removed the FPS cap to check overall performance, it never went over 60 until I disabled the above code and tried a screen sized JFrame instead. It looks damn good too. Not a single jitter or break in the animations. 100% smooth rendering. A few things to consider: I am using the Direct3D Java properties: sun.java2d.d3d=true sun.java2d.noddraw=false sun.java2d.accthreshold=0 and the infinite sleeping thread (hi-res timer) hack. My graphics driver is in fact set to always enforce VSync (that's how I've gotten the best performance in games) on 3D applications, so I wouldn't necessarily expect this to work on PCs that don't have that setting. Some system specs: OS: Windows 7 CPU: i7-3770 GPU: NVidia GeForce GTX-560 GC (factory overclocked) 2GB VRAM RAM: 16GB Forgive me if this is some kind of old-as-the-hills common knowledge. I thought it was pretty interesting. Has anyone else ever noticed this and/or can you confirm it on your system?
|
|
|
|
|
3
|
Game Development / Game Mechanics / Re: Resolving Pixel Perfect Collisions
|
on: 2013-03-09 02:49:39
|
|
The collision checking actually comes after the update, before the rendering. The problem is, the event will fire, but nothing will be done until the next tick. The order really doesn't matter though. Either it will show collision too early or too late.
The problem is computing that collision point when you aren't dealing with just boxes or even polygons but bitmaps of loaded sprite images. Remember this is pixel-perfect collision detection. So again, I'm stuck on how to actually GET the point of collision and resolve the position of the colliding entity to that point.
|
|
|
|
|
4
|
Game Development / Game Mechanics / Resolving Pixel Perfect Collisions
|
on: 2013-03-08 22:21:38
|
|
I have a pixel-perfect collision detection system that uses a bitmask for loaded sprite images and checks for overlap in the binary digits using a kind of bitwise analysis algorithm.
It works quite nicely, and it only has to run when the cheap bounding box collision code returns a valid collision area.
The bounding box collision code computes the collision area between the two entities' bounds and returns null if there is no collision.
The problem I have now is how to resolve these collisions. If I'm updating a moving ball 20 units per tick, I don't want it moving 10-15 units into another entity and being rendered before bouncing or stopping (obviously).
What's the best method with this kind of pixel-perfect collision to resolve collisions? The best idea I've come up with so far is a simple loop to guess and check until you get as close as needed to the collision location, but this seems kind of risky and would most likely scale quite poorly. Any other ideas?
Thanks in advance for your help!
|
|
|
|
|
5
|
Game Development / Game Mechanics / Implementing 2D Light
|
on: 2013-01-26 18:27:55
|
|
I believe I've posted a topic similar to this before, but it was quite a while ago. My goal is also somewhat more narrow this time.
I'm aiming to create a lighting system that uses an image overlay over the main rendering canvas to create light/shadow effects.
I'm stuck primarily at how to actually efficiently draw the light geometry to the image. I'm trying to avoid pixel-by-pixel iteration because it causes too much performance drop in the context of the rendering engine already.
Mathematically, I was planning on just using an inverse square relationship for light traveling:
L = A/(d^2) | L is luminance, A is absolute luminance (at one unit distance), and d is distance.
The main problem is applying this efficiently AND detecting light collision with entities in world space.
In other words, how can I calculate the shadow area (especially for objects that aren't squares...) and then apply that lighting change to the image?
I'm looking for ideas and suggestions here, no specific method. If you have any ideas that don't involve the light overlay, that's fine too. I'm concerned about its performance anyway. Thanks in advance for your help!
|
|
|
|
|
8
|
Game Development / Game Mechanics / Re: Java Unpacking Native Image
|
on: 2013-01-23 21:04:40
|
|
Ok that certainly clears things up. Thank you!
I'm a bit confused though... I do get a performance improvement by using CompatibleImage for the on-screen image buffer. You think I should switch to TYPE_INT_ARGB_PRE?
|
|
|
|
|
9
|
Game Development / Game Mechanics / Best Method to Implementing Smooth Animation
|
on: 2013-01-23 20:56:49
|
|
What is the best method to programming more advanced 2D animations in Java, like skeletal movement and such?
For example, in a 2D game, a character walking animation with fluid leg movement as opposed to flipping between 3-4 animation sprites.
Is it best to just make a TON of sprites? Or is there a better way?
|
|
|
|
|
10
|
Game Development / Game Mechanics / Re: Java Unpacking Native Image
|
on: 2013-01-11 00:53:15
|
BufferedImage.setRGB()?
setRGB causes the BufferedImage to become unmanaged, which is REALLY REALLY slow. The only way to manually modify pixels and maintain the advantages of keeping the data managed in video memory is through modifying the data array directly. Er, I think you got that all backwards!  I just tried commenting out the data fetching code and replaced it with setRGB and getRGB. It dropped my solid 60fps rendering to 4fps. 
|
|
|
|
|
11
|
Game Development / Game Mechanics / Re: Java Unpacking Native Image
|
on: 2013-01-11 00:49:04
|
BufferedImage.setRGB()?
setRGB causes the BufferedImage to become unmanaged, which is REALLY REALLY slow. The only way to manually modify pixels and maintain the advantages of keeping the data managed in video memory is through modifying the data array directly. Er, I think you got that all backwards!  Really? That's mainly based on information I've gathered form other people and Sun's documentation. Can you be a little more specific?
|
|
|
|
|
12
|
Game Development / Game Mechanics / Re: Java Unpacking Native Image
|
on: 2013-01-11 00:23:43
|
BufferedImage.setRGB()?
setRGB causes the BufferedImage to become unmanaged, which is REALLY REALLY slow. The only way to manually modify pixels and maintain the advantages of keeping the data managed in video memory is through modifying the data array directly.
|
|
|
|
|
13
|
Game Development / Game Mechanics / Java Unpacking Native Image
|
on: 2013-01-10 23:08:22
|
I use the compatible native image returned from GraphicsConfiguration for the buffers in my rendering code. The problem I now have with this, is how can I unpack/pack these pixels? I need to modify the RGB values.... but it doesn't seem to be working even though the DataBuffer is still of type DataBufferInt. The integer pixels appear to be packed in a different format than TYPE_INT_RGB. Is there a more format independent method to unpacking/packing int pixels than: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| public static int[] unpackInt(int argb, int type) { int[] vals = null; int p1 = 0; int p2 = 1; int p3 = 2; int p4 = 3; switch (type) { case TYPE_RGB: vals = new int[3]; vals[p1] = argb >> 16 & 0xFF; vals[p2] = argb >> 8 & 0xFF; vals[p3] = argb & 0xFF; break; case TYPE_RGBA: case TYPE_ARGB: vals = new int[4]; vals[p4] = argb & 0xFF; vals[p3] = argb >> 8 & 0xFF; vals[p2] = argb >> 16 & 0xFF; vals[p1] = argb >> 24 & 0xFF; break; default: throw (new IllegalArgumentException( "type must be a valid field defined by ColorUtils class")); } return vals; }
public static int packInt(int... rgbs) { if (rgbs.length != 3 && rgbs.length != 4) { throw (new IllegalArgumentException( "args must be valid RGB, ARGB or RGBA value.")); } int color = rgbs[0]; for (int i = 1; i < rgbs.length; i++) { color = (color << 8) + rgbs[i]; } return color; } |
|
|
|
|
|
16
|
Game Development / Game Mechanics / Best Method For Scaling Image Resources/Sprites
|
on: 2013-01-10 05:28:35
|
|
My monitor is 1920x1080, so everything I create on it will be how it looks on a 1920x1080 monitor.
This isn't, however, necessarily the "best" or highest resolution.
Is it still best then to scale everything to the user's resolution from my own? And should scaling be done only down, or up as well?
How to create the graphics for a game has always been my biggest issue mainly for this reason.
If you are simply going to scale everything up or down, what is the best method to doing this? AffineTransform or scaling each image individually when it's loaded?
|
|
|
|
|
17
|
Game Development / Newbie & Debugging Questions / Re: Rendering Loop Stuttering On Random App Instances
|
on: 2013-01-10 05:05:48
|
|
I was able to bring the stuttering down to a reasonable minimum on Linux, and nearly eliminate it on Windows.
I find that playing with various things such as BufferStrategy buffer count, render ops, and max-updates in the fixed timestep can make a difference depending on the platform. That seems reasonable. It isn't uncommon that you have to adjust video settings in a game to get optimal results.
Setting the JVM flag -Dsun.java2d.opengl=true REALLY helps. I highly recommend that to anyone having slow rendering/stuttering problems in Java2D.
|
|
|
|
|
18
|
Game Development / Newbie & Debugging Questions / Re: Rendering Loop Stuttering On Random App Instances
|
on: 2013-01-07 21:14:12
|
Could be Swing, the code, system clock or a number of things.
A notorious cause can be the inaccurate windows clock which you can force to use a more accurate one by making an infinite daemon loop. The "windows daemon fix" which some call it.
I am actually already using that infinite daemon timer fix. It does seem to work quite nicely for the Windows timer. After switching the buffer and display BufferedImages to native image type (Graphics.createNativeImage I think is the method), and adding the -Dsun.java2d.opengl=true VM argument, the stuttering seems to be mostly gone on Windows. It does still occur on Linux, however. That actually surprises me quite a bit.... I would've expected Linux to perform better. That may have something to do with my Graphics driver on Linux. Not sure. Are there any known issues with Java2D on Linux?
|
|
|
|
|
19
|
Game Development / Newbie & Debugging Questions / Re: Rendering Loop Stuttering On Random App Instances
|
on: 2013-01-06 18:32:48
|
You can't have a "fixed variable" timestep. It's one or the other.  Of course we need code snippets. We can't read your mind.  My mistake. That was a stupid miswording. It's a fixed timestep (I'll fix that in the question). There's a lot of different code snippets, so I figured we should start with speculation and theory and then I can get you any specific sections of code you need (i.e. rendering logic, timestep loop, etc.) How much does it jump/stutter? Could be a rounding error (or lack thereof) when drawing or faulty interpolation.
That or it could just be Swing, if you're using that.
I'm using Math.round when applying the interpolation to rendering positions. That should work fine right? I am using Swing. The goal of the engine was to use pure Java2D. Surely it can work....
|
|
|
|
|
20
|
Game Development / Newbie & Debugging Questions / Rendering Loop Stuttering On Random App Instances
|
on: 2013-01-06 06:58:21
|
|
I'm using a fixed timestep in my rendering loop to interpolate the render positions and maintain a steady framerate of 60fps and update interval of 30tps.
I have a test animation that moves a single image across the screen in a linear path, checking for a minimum timestep on each update.
The odd thing is, the animation is smooth on a majority of the times I launch the program, but sometimes it begins to stutter (i.e. the image "shakes" while moving or jumps ahead/behind in its position a little bit).
What I don't understand, is that the frame-rate monitor has the frame rate and update rate staying steady even while the image is stuttering during the animation.
What could be causing this? And why is it so inconsistent between application instances?
If you need any code snippets, let me know.
Thanks in advance for your input!
|
|
|
|
|
23
|
Game Development / Newbie & Debugging Questions / Re: Blending Alpha Pixels?
|
on: 2012-12-08 22:37:19
|
I suspect there is something wrong with your code or game loop if you're getting such poor performance. Iterate through your pixels with a single loop, instead of two: 1 2 3 4 5 6
| for (int i=0; i<WIDTH*HEIGHT; i++) { int y = i / WIDTH; int x = i - WIDTH*y; ... } |
I tried using the single for loop as you suggested and it hurt performance even more. It knocked it down to 48fps with only 3 render jobs.
|
|
|
|
|
25
|
Game Development / Newbie & Debugging Questions / Blending Alpha Pixels?
|
on: 2012-12-08 19:14:46
|
Consider the following code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| for(int y = 0; y < ht; y++) {
int yp = ypos + y;
if(yp >= pri.getHeight() || yp < 0) continue;
for(int x = 0; x < wt; x++) { int xp = xpos + x;
if(xp >= pri.getWidth() || xp < 0) continue;
int pos = yp * pri.getWidth() + xp; if(pos < 0 || pos >= pixels.length) continue; int cv = pixels[pos]; int nv = colors[y*wt + x]; double alpha = nv >> 24 & 0xFF; if(alpha < 255) { nv = ColorUtils.packInt(255, cv >> 16 & 0xFF, cv >> 8 & 0xFF, cv & 0xFF); nv = (int) Math.round(cv * (alpha / 255) + nv * (1 - alpha / 255)); } pixels[pos] = nv; } } |
As you may be able to guess, I'm attempting to blend pixels that are translucent. This method doesn't appear to be working very well, however. Given pixel value 'a' (current set value in image) and new translucent value 'b' (let's assume alpha of 200 or so), how do you blend the two pixels so that 'a' still appears through 'b' but with modified coloring (i.e red + blue = purplish)?
|
|
|
|
|
26
|
Game Development / Newbie & Debugging Questions / Re: Rendered Image "Chugging" While Moving
|
on: 2012-11-25 19:58:22
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| @Override public void render(RenderControl rc) { final int INTERVAL = 20;
long mark, diff; if ((diff = (mark=System.currentTimeMillis()) - last) >= INTERVAL) { x+=5; y+=5; last = mark; last -= (diff - INTERVAL); } rc.render(x, y, img.getWidth(), img.getHeight(), data); } |
This seems to work a little better but there's still some stuttering.
|
|
|
|
|
29
|
Game Development / Newbie & Debugging Questions / Rendered Image "Chugging" While Moving
|
on: 2012-11-25 19:08:42
|
The Java2D engine I'm building uses a render loop that iterates over a Set of Renderable objects. It calls render(RenderControl) on each Renderable object. It's then up to each object to call render(int,int,int,int,int[]) so that the image data is added into the main BufferedImage's raster. In a test object that just renders an image on screen and increments the position based on how much time has passed (to animate it), I have this code: 1 2 3 4 5 6 7 8 9 10 11
| @Override public void render(RenderControl rc) {
if (System.currentTimeMillis() - last >= 20) { x+=4; y+=4; last = System.currentTimeMillis(); } rc.render(x, y, img.getWidth(), img.getHeight(), data); } |
Where img is a BufferedImage representing the image loaded previously using ImageIO.read. When this runs, however, the moving image kind of chugs in it's movement. It freezes or relapses in its path around every second, even though the frame rate is consistently 55-60fps (capped using Thread.sleep). Is there something wrong with the way I'm doing this? Should the position changing code be executed in a separate thread? Let me know if you need any more information. Many thanks in advance! Let me know if you need any more information,
|
|
|
|
|
30
|
Game Development / Newbie & Debugging Questions / Best Method For Rendering?
|
on: 2012-06-28 05:18:44
|
|
I'm trying to figure out the best method to rendering data on screen... and ideally NOT by just using drawImage.
Does anyone have a particular way of doing it that is scalable, reliable and has good performance?
I'm not only referring to the act of shifting the data, I'm also referring to the whole architecture. What calls what, in what order, and how are the Objects organized?
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|