Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1] 2 3 ... 21
1  Game Development / Newbie & Debugging Questions / Re: Slick2d transitions on: 2011-10-23 22:39:09
you have changeState() or State.enter() or something like that... check out the examples and tutorials for it
2  Game Development / Game Mechanics / Re: Idea for collision detection between arbitrary shaped objects in 2D on: 2011-10-21 21:48:57
dont' know about java.awt.geom.Area but Slick2d's Polygon class has intersect() and contains() and it's all implemented to be fast as possible. I suggest using circle vs circle or rectangle vs rectangle for (extreamly) fast result.
3  Java Game APIs & Engines / OpenGL Development / Re: using multitexture for lightmap in shaders - how to use common lightmap for all? on: 2011-10-21 14:34:07
Nice point!
Glad the discussion went a little deeper then just finding the first solution to it, I always learn something from this kind of discussions.

I still think second pass is much slower whatever you (in practice) do. Let me explain.
Your calculation on 900 sprites is far from complete... you're just counting pixels drawn and ignoring the rest of the pipeline.
Quote
What you do: cost = numSprites * x where x is approximately 1.1-1.5 meaning a higher cost per sprite
Second pass: cost = numSprites + secondPassTime
this is much more appropriate conclusion... the main point in this that we are talking about is that "secondPassTime" is unknown

How I think it goes is:
one pass cost: pixelNumber * (pipeline calcs for it + my additional sampling: 2 additions, 2 divisions and sampling = 5 operations)
2 pass cost: pixelNumber * piple calcs for it * 2

this is where it gets interesting... as it's all multiplied but "my additional sampling" are 5 very fast operations, while in 2 pass scenario pixel number multiplied by 2 and is huge (1920x1080). Additionaly "pipeline calcs for each pixel" also must be huge with all that tests and transformations (matrix transformations, depth test, alpha test, scissor test, blending, vertex and frag shaders, ...).

So final numbers for let's say 100 objects may be in domain of:
one pass cost: (1920*1080 + 100 * 48*48) * (1000 + 5)
2 pass cost: (1920*1080 + 100 * 48*48) * 1000 + 1920*1080 * 1000
All the big cost as I see it is in the pixels and the pipeline operations itself.
Of course this is all made up to a scale I think represents the speed of it, I don't know exactly or even approx. if there are 1000 operations for a pixel to go through whole pipeline (in fact pixels don't go through it, they are created, but let's say operation cost of rendering a single pixel to screen)
I think my point is clear, I think for second pass to be worth it number of objects would have to be in millions.

All that said.. I could simply test it Smiley .. just comment that line on the shader and make a second draw with blending. Smiley I'll report the results.
4  Java Game APIs & Engines / OpenGL Development / Re: using multitexture for lightmap in shaders - how to use common lightmap for all? on: 2011-10-20 20:44:16
Ok, tihis is the final frag shader with camera in mind. Camera position is passed as normalized [0..1] values relative to texture size. (e.g. camera position x of 0.25 would mean we are starting the render at three fourths along x axis).

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
uniform sampler2D texture;
uniform sampler2D lightMap;
uniform vec2 lightMapSize;
uniform vec2 cameraPosition;

layout(origin_upper_left) in vec4 gl_FragCoord;

varying vec2 VaryingTexCoord0;

out vec4 fragColor;

void main (void)
{
    fragColor = texture2D(texture, VaryingTexCoord0.st);
    vec2 lightmapTextureCoordinates = vec2(gl_FragCoord.x / lightMapSize.x + cameraPosition.x, gl_FragCoord.y / lightMapSize.y + cameraPosition.y);
    fragColor *= texture2D(lightMap, lightmapTextureCoordinates);
}
5  Java Game APIs & Engines / OpenGL Development / Re: using multitexture for lightmap in shaders - how to use common lightmap for all? on: 2011-10-20 16:17:16
Got it! Solution is so simple Smiley
Tnx everyone for chiping in, I hope this will be some use to you.

So I finally realised texture2d(texture, texCoords) takes texCoords as normalized [0..1] .. and then all became much simpler. By using gl_FragCoord and screen width and height, you can calculate where your pixel is on the screen in [0..1] range and apply use that coordinates for lightmap texture (which is fullscreen).

Fragment shader:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
uniform sampler2D texture;
uniform sampler2D lightMap;
uniform float screenWidth;
uniform float screenHeight;
varying vec2 VaryingTexCoord0;

out vec4 fragColor;

void main (void)
{
    fragColor = texture2D(texture, VaryingTexCoord0.st);
    fragColor *= texture2D(lightMap, vec2(gl_FragCoord.x / screenWidth, gl_FragCoord.y / screenHeight));
}


Only thing left to do (which I forgot about before I came here to brag how I solved it Smiley ) is to adjust it by camera position, and that is just adding another vector to the result.
6  Java Game APIs & Engines / OpenGL Development / Re: using multitexture for lightmap in shaders - how to use common lightmap for all? on: 2011-10-20 04:22:46
Actually I wasn't so concerned with objects as they are mostly small images like 48x48... but at the end you must draw the lightmap which is fullscreen 1920x1080, and with blending on it affects every pixel and that's a big slowdown (I assume) as OpenGL will recalculate every pixel and combine with existing one. A combined calculation in shader eliminates that second fullscreen render of lightmap.
Note I didn't actually tested that scenario but I did render the scene to FBO and then to screen (which is 2x fullscreen drawing) which was slow.. that combined with some knowlage about what is fast in OpenGL I think drawing lightmap afterwards will be noticeably slower then mix in shader approach. Ah well... it seems only thing that's left to do is to actually implement the thing and try it out Smiley
7  Java Game APIs & Engines / OpenGL Development / Re: using multitexture for lightmap in shaders - how to use common lightmap for all? on: 2011-10-19 22:54:34
You basically just want to sample the player location from the light map? Why don't you just do it backwards? Load or generate a lightmap and just draw it on top of the complete scene. Would that give you the effect you want?

yeah but that is drawing fullscreen resolution texture 2 times with blending. First time for unlit and second time for the lightmap. Wouldn't be much faster if I combine it within shader itself with only one pass?

@Rejechted
tnx for the link! I'll start reading now Smiley
8  Java Game APIs & Engines / OpenGL Development / Re: using multitexture for lightmap in shaders - how to use common lightmap for all? on: 2011-10-19 16:57:27
Thank you all for your advices!

Yes it's fully 2d game and I don't use 3d models at all. So far I only want to do static lighting with global lightmap as described, later on I was thinking I could add dynamic lights by drawing on the lightmap (texture). And I don't need shadows yet, maybe in another game.

Quote from: cylab
Sure you can. If your lightmap coords for example are in the range of [0.0;0.0] to [0.8;0.6] you can calculate the player position in the lightmap with posX/lmWidth*lmRangeX and posY/lmHeight*lmRangeY (e.g 100/800*0.8 resp. 100/600*0.6 => [0.1;0.1]) do the same with the size of your players sprite (e.g. 50/800*0.8 and 50/600*0.8 => [0.05;0.05]), add the position offset and you have the range of the texCoords you need in your lightmap (e.g. [0.1;0.1] to [0.15;0.15] )

Yes exactly, very good example, but I thought I could skip this kind of calculation as all numbers that I need are available, it's just I don't know how to calculate it in shader. Thought that calculating in shader will be faster as you don't have to change the state of opengl (and that is slow as I heard) by making lots of glMultiTexCoords() calls and the second reason is that I could be nice if you can just add the lighting like that with the shader and lightmap to your game without other modifications. You could just add lightmap and shader in your game and that's it, it would work so other game could use it with no need to calculate extra glMultiTexCoord() calls.

I'm working on 2 approaches now:
1) send lightmap position as uniform and multiply it with gl_ModelViewMatrix
2) send lightmap position in pixels on screen and use gl_FragCoords to calculate proper texture coordinates
Any advices are still welcome. I'll keep you updated here if make it work.
9  Java Game APIs & Engines / OpenGL Development / using multitexture for lightmap in shaders - how to use common lightmap for all? on: 2011-10-18 21:35:41
Hello.

So I've got this big 2d image for map and to implement lighting I got the lightmap image for it and a shader. Lightmap image is a simple black-white image. I know how to use multitexturing in a "normal" way whay, when you bind the texture and set glMultiTexCoords() but what when you want to use that texture as lightmap for all your objects you are drawing? This lightmap must be used when drawing other objects over the map, for example when drawing a player over the map on (x,y) position, I must use lightmap (x,y) position. The problem is I have no idea how to resolve object coordinates to correct texture coordinates in shader.

For example: Both map image and lightmap image are 800x600. I draw the map and use lightmap normally with multiTexCoords(). Now I want to draw player that is located at (100,100), but this time I can't set the lightmap texture with glMultiTexCoords(). How to calculate proper lightmap coords in shader?

this is my fragment shader now:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
uniform sampler2D texture;
uniform sampler2D lightMap;
varying vec2 VaryingTexCoord0;

out vec4 fragColor;

void main (void)
{
    // original texture
    fragColor = texture2D(texture, VaryingTexCoord0.st);

    // common lightmap affects lighting the pixel
    fragColor *= texture2D(lightMap, NEED_THIS.st);
}


Any ideas on how to resolve texture coordinates I must use in second step?
Thank you all for your time.
10  Game Development / Newbie & Debugging Questions / Re: How to get folder paths inside a jar file? on: 2010-11-11 11:59:20
I was just wondering about use case for that situation you have CyanPrime ... how come you don't know structure of a jar at runtime, do you change it in the game or do you add new resources dynamically this way?
11  Java Game APIs & Engines / OpenGL Development / Re: Colored OpenGL Lights and lighting stuff on: 2010-11-10 21:29:55
1  
            FloatBuffer ltDiffuse2 = allocFloats(new float[] { 0.5f, 5.0f, 0.5f, 1.0f });

This line was causing your problem: red and blue were multiplied by 0.5, hence red and blue tints showed up in the rendering.

yes but I wanted a light that would show an object, but in a greenish color, not to hide everything that is not green. Like if you have lamp with a green lightbulb.

BTW: green was just multiplied by 1.0, not 5.0
not true, values beyond 1.0 are not cut off and are multiplied so you get a larger radius / intensity of the light, just tested it. With 1.0 I see 3x3 of ships, with 5.0 I see ships like on screenshot that have green engines.
12  Java Game APIs & Engines / OpenGL Development / Re: Colored OpenGL Lights and lighting stuff on: 2010-11-10 16:35:09
As GL_LIGHT is outdated I was pointed to use shaders ... so nevermind about light questions but I'll leave it in case somebody else with similar problems stumbles upon it
13  Game Development / Newbie & Debugging Questions / Re: Which is better? on: 2010-11-09 23:45:41
for such small examples, I prefer the 2nd one.. as it's logic is easier read in my mind... if () doSomething, else doOther
14  Game Development / Game Mechanics / Re: Collision detection efficiency on: 2010-11-09 23:41:40
As far as profiling I personally didn't have much success as profiling itself used so much time it was useless and inaccurate (used Eclipse TPTP, or whatever is called)

If profiling doesn't work for you, you can always turn off feature by feature and see the impact on the FPS. For example turn off collision detection and see FPS difference.
15  Java Game APIs & Engines / OpenGL Development / Colored OpenGL Lights and lighting stuff on: 2010-11-09 23:15:10
Hello

I'm learning OpenGL lighting and I can't seem to figure out couple of things. I've tried many tutorials and googled, but it's all so much theory in general and no details and examples. My questions are:

1) how is radius of the light determined?
I noticed it grows with moving light on z-axis away from x=0, y=0 plane, but also when changing light attenuation (falloff) formula and also light color values... so is there a simple rule of thumb how to lit 100 pixels / units or something like that?

2) why diffuse and other color values are fully strong even beyond 1.0f for RGB values?
I thought 1.0 is the max... but you can put more

3) how to do colored lights?
for example for the bottom light in the screenshot I wanted to be green, but it came out weird only few pixels of the ship showing green (engines) and others are dark red...

Thank you all for your time.. and now screenshot and code that made lights in it is below the screenshot

For creating light in 2d game (Kev's space invaders 104 lwjgl example) I use the code at the end, which produces this result:


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  
            GL11.glEnable(GL11.GL_LIGHTING);
            FloatBuffer ltDiffuse = allocFloats(new float[] { 2.0f, 2.0f, 2.0f, 1.0f });
            FloatBuffer ltAmbient = allocFloats(new float[] { 0.0f, 0.0f, 0.0f, 0.0f });
            FloatBuffer ltSpecular = allocFloats(new float[] { 0.0f, 0.0f, 0.0f, 1.0f });
            FloatBuffer ltPosition = allocFloats(new float[] { 250.0f, 120.0f, 10.0f, 1.0f });
//          GL11.glLightf(GL11.GL_LIGHT0, GL11.GL_SPOT_CUTOFF, 70);
            GL11.glLight(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, ltDiffuse); // color of the direct illumination
            GL11.glLight(GL11.GL_LIGHT0, GL11.GL_SPECULAR, ltSpecular); // color of the highlight
            GL11.glLight(GL11.GL_LIGHT0, GL11.GL_AMBIENT, ltAmbient); // color of the reflected light
            GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, ltPosition);
            GL11.glLightf(GL11.GL_LIGHT0, GL11.GL_CONSTANT_ATTENUATION, 0.0f);
            GL11.glLightf(GL11.GL_LIGHT0, GL11.GL_LINEAR_ATTENUATION, 0.0f);
            GL11.glLightf(GL11.GL_LIGHT0, GL11.GL_QUADRATIC_ATTENUATION, 0.00001f);
            GL11.glEnable(GL11.GL_LIGHT0); // Enable the light (GL_LIGHT1 - 7)

            FloatBuffer ltDiffuse2 = allocFloats(new float[] { 0.5f, 5.0f, 0.5f, 1.0f });
            FloatBuffer ltAmbient2 = allocFloats(new float[] { 0.01f, 0.01f, 0.01f, 1.0f });
            FloatBuffer ltSpecular2 = allocFloats(new float[] { 0.0f, 5.01f, 0.0f, 1.0f });
            FloatBuffer ltPosition2 = allocFloats(new float[] { 500.0f, 400.0f, 10.0f, 1.0f });
            GL11.glLight(GL11.GL_LIGHT1, GL11.GL_DIFFUSE, ltDiffuse2); // color of the direct illumination
            GL11.glLight(GL11.GL_LIGHT1, GL11.GL_SPECULAR, ltSpecular2); // color of the highlight
            GL11.glLight(GL11.GL_LIGHT1, GL11.GL_AMBIENT, ltAmbient2); // color of the reflected light
            GL11.glLight(GL11.GL_LIGHT1, GL11.GL_POSITION, ltPosition2);
            GL11.glLightf(GL11.GL_LIGHT1, GL11.GL_CONSTANT_ATTENUATION, 0.8f);
//            GL11.glLightf(GL11.GL_LIGHT1, GL11.GL_LINEAR_ATTENUATION, 0.0f);
//            GL11.glLightf(GL11.GL_LIGHT1, GL11.GL_QUADRATIC_ATTENUATION, 0.00001f);
            GL11.glEnable(GL11.GL_LIGHT1); // Enable the light (GL_LIGHT1 - 7)
16  Games Center / Archived Projects / Re: Technopolies on: 2009-02-28 16:55:15
bump!

Me and my friends are doing very similar game, just not mmorpg but more like an arcade. We would love to see the resources and especially the source code if it that is ok and anybody from the project can read this after that long time... thank you.

marko (at) werebytes.com
17  Game Development / Newbie & Debugging Questions / save and load game on: 2008-08-07 11:41:27
Hello.
I want to implement saving and loading (from file) in my game that uses Kev's Slick engine
I searched the forums, googled and found nothing useful...

So I am wondering what is the simplest way?
a) serialize all my objects for save and deserialize for load
b) manually save data in some file, like xml, and restore it manually by parsing
c) something else...

Any suggestions?
18  Java Game APIs & Engines / jMonkeyEngine / Re: What tools are available for jME at the moment? on: 2007-08-23 13:23:45
plays fine here... this is all Info I was able to get from it: Video: XVID 640x480 25.00fps 117Kbps [Video 0]
19  Game Development / Newbie & Debugging Questions / Re: repaint with swing - paintComponent method never gets called... on: 2007-08-21 07:30:09
my main JFrame has the setSize attribute set, no setLocation but it renders fine....... as for the call to repaint in the start/run method, I tried placing it in there and still no joy.

I wasn't talking about JFrame, I was talking about your container and DealCards. Everything must be visible, put setVisible(true) just in case for every component. By default if you make JFrame visible then all children will be visible, but if you used some unstandard layout manager as null layout manager then you have to set sizes manually, I'm not talking about JFrame but for container.

edit: here's a simple example, if you uncomment any setVisible(false) or setLayout(null) the button will not appear

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  
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class ComponentVisibility extends JFrame {
   
    JPanel container = new JPanel();
    JButton button = new JButton("test");
   
    public ComponentVisibility() {
        super("Component Visibility");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setBounds(200,200,300,400);
        setContentPane(container);
//        container.setLayout(null);
        container.add(button);
//        container.setVisible(false);
//        button.setVisible(false);
        setVisible(true);
    }
   
    public static void main(String[] args) {
        new ComponentVisibility();
    }

}
20  Game Development / Newbie & Debugging Questions / Re: repaint with swing - paintComponent method never gets called... on: 2007-08-20 22:38:57
In reply to Kova, the paintComponenent method in my super class is set to protected too. The JFrame state is visible and other calls to paintComponent from GameWindow are executed and drawn in the JPane.

how about size? Did you set the size?
edit: clarification, maybe you are using null layout manager and in that case you need to set size and position manually as I remember or they will be zero and paintComponent() wouldn't get called (?) ... try to do it manually
21  Game Development / Newbie & Debugging Questions / Re: repaint with swing - paintComponent method never gets called... on: 2007-08-20 20:48:01
hmm... are you sure you are overriding it? Maybe method from super class has public modifier and not protected? Didn't ever tried that so I don't know if it matters.
Well you said it already works for GameWindow so this doesn't matter...

Also, you cannot go into paintComponent() while debugging because paintComponent() is called from AWT-Swing thread (EDT?), it isn't called from repaint() in your thread. Repaint() only queues call to paintComponent() in Swing thread.

I don't know how we can help you anymore... make sure that it's visible (setVisible(true)) and that is added to a visible container.

If you don't solve it, instead if this build simplest JPanel with custom painting and try to implement it. If it works then build it little by little to your class.
22  Game Development / Newbie & Debugging Questions / Re: repaint with swing - paintComponent method never gets called... on: 2007-08-19 23:00:20
your calling hierarchy guess is correct... repaint() calls paintComponent() but only not instantly, as fast as it can...
maybe your bDealing is false always? Put some output before it to check this and if paintComponent() really gets called, you don't need debugger...
one more thing that could make paintComponent() not get called is that you never added it to a visible container... also check if repaint() really gets called by putting some output before it.
23  Game Development / Networking & Multiplayer / Re: How to get a job as a network game programmer on: 2007-08-18 07:05:38
nice article, can't wait for other parts!
24  Discussions / General Discussions / Re: Next 3D engine generation .... impressive on: 2007-08-06 10:37:40
I was not so impressed by the engine itself as the level editor... seems like something you can give to designer and not programmers to make the complete world
25  Game Development / Newbie & Debugging Questions / Re: opengl video tutorials on: 2007-08-05 23:27:35
site is good, but not as good as I expected from video tutorial... the guy just scrolls through code and explains it. I expected he'll be writing the code and showing how game was built.
26  Discussions / General Discussions / Re: Next 3D engine generation .... impressive on: 2007-08-04 08:13:07
amazing, but what hardware it needs to run smoothly?
27  Game Development / Networking & Multiplayer / Re: Sending player positions through the Server on: 2007-08-03 13:11:21
for such simple example, it's enough that you set up server to send data to clients every X seconds, and clients do the same just sending to server their data. Generally it shouldn't when clients send their messages and server sends theirs, as long as messages are being sent in regular intervals. By this I mean it doesn't matter if server sends 0.1 seconds after he gets messages from client and such.
I just created sending thread that was doing .wait(X) and sending all queued data to all clients.... this way if you need to send an instant message you can always put that instant message to sending queue and wake up the thread... it's best when you figure it out by yourself.
28  Discussions / Miscellaneous Topics / Re: Anyone besides me really dislike Eclipse? on: 2007-08-02 13:24:52
Nope, the autocomplete in Eclipse sucks. An example: Say we have an object "fred". Type fred, followed by a full stop. The autocomplete pops up. Type the first few chars of the member you want, then say you make a mistake and hit backspace. You lose the lot, and have to delete what you've typed back to "fred" and start again.

huh? if you make a mistake and hit backspace you delete one character, nothing disappears (at least on my eclipse, but it's default behavior)
29  Discussions / Miscellaneous Topics / Re: MUL Discussion on: 2007-07-31 00:58:14
still no update to MUL thread? ... it's all here, just move it there?
30  Discussions / Miscellaneous Topics / Re: Anyone besides me really dislike Eclipse? on: 2007-07-31 00:56:39
Only for addons, and patches to Eclipse, not when you have to jump a version, like 3.2.2 -> 3.3.0

hmm, I saw an option to upgrade to new versions like this... it's turned off by default, look it up
I know it's definitely mentioned in subclipse upgrade instructions as I saw it and upgradet subclipse from 1.2 to 1.4 like that.
Pages: [1] 2 3 ... 21
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (45 views)
2014-10-17 03:59:02

Norakomi (36 views)
2014-10-16 15:22:06

Norakomi (27 views)
2014-10-16 15:20:20

lcass (31 views)
2014-10-15 16:18:58

TehJavaDev (61 views)
2014-10-14 00:39:48

TehJavaDev (61 views)
2014-10-14 00:35:47

TehJavaDev (51 views)
2014-10-14 00:32:37

BurntPizza (67 views)
2014-10-11 23:24:42

BurntPizza (39 views)
2014-10-11 23:10:45

BurntPizza (81 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!