Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (753)
Games in Android Showcase (228)
games submitted by our members
Games in WIP (842)
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
1  Discussions / General Discussions / Re: Java and Algebra. on: 2014-02-11 05:35:14
Algebra isn't as important as basic logic and being able to think logically.  But if you are serious about getting better just practice!  I'm a professional mathematician, so you can trust me  Grin
2  Game Development / Newbie & Debugging Questions / Re: Framebuffer Object vs. Vertex Buffer Objects on: 2014-02-03 17:56:47
They are not the same thing.  I'll assume you already know what VBOs are. FBOs are basically used for if you want to render to someplace other than the screen.  For example. suppose you had a scene with a TV in it and you wanted to have some 3d characters on the TV.  So you could render the TV scene to a texture (using a FBO) and then render that texture on the TV. 

See this image here (just pulled from google image search):

Click to Play

So the teapot was rendered to a texture and then that texture was placed on a cube.  There are of course many other uses for FBOs, that's just a basic one.  Hope that helped!
3  Games Center / WIP games, tools & toy projects / Re: Renoria - Java MMORPG on: 2014-01-28 17:55:42
This game is looking great!  I'm very impressed indeed.  Were you able to find anyone to do your music for you?
4  Discussions / General Discussions / Re: [Solved (mostly)] Dealing with billboards and Z buffers on: 2014-01-21 06:24:10
I think that the best possible result would have to use ray casting to project the billboarded quad onto a vertical facing quad and find the depth value that way.  Then each pixel will be have the exact depth that it "ought" to have.  For my purposes this is overkill, however others might still be interested is something like this.
5  Game Development / Newbie & Debugging Questions / Re: How to get the bullets to go towards mouse? on: 2014-01-20 18:18:43
Here is a link to a previous post I made helping someone else with the same problem:
6  Game Development / Game Mechanics / Re: Rotate camera around origin problem on: 2014-01-19 19:12:13
That is a good point.  I guess it all depends on how his rotation method is actually implemented.  Are you using cross products to compute the up, forward, and right vectors of the camera?  If so, make sure that you are not taking a cross between two parallel vectors as this will output the zero vector and is an undesirable result.
7  Game Development / Game Mechanics / Re: Rotate camera around origin problem on: 2014-01-19 16:26:36
Use this method to convert from a quaternion to a rotation matrix:

public static Matrix4f rotationFromQuaternion(Quaternion q) {
   Matrix4f mat = new Matrix4f();

   float xSq = q.x * q.x;
   float ySq = q.y * q.y;
   float zSq = q.z * q.z;
   float wSq = q.w * q.w;
   float twoX = 2.0f * q.x;
   float twoY = 2.0f * q.y;
   float twoW = 2.0f * q.w;
   float xy = twoX * q.y;
   float xz = twoX * q.z;
   float yz = twoY * q.z;
   float wx = twoW * q.x;
   float wy = twoW * q.y;
   float wz = twoW * q.z;

   mat.m00 = wSq + xSq - ySq - zSq;
   mat.m10 = xy - wz;
   mat.m20 = xz + wy;
   mat.m30 = 0;
   mat.m01 = xy + wz;
   mat.m11 = wSq - xSq + ySq - zSq;
   mat.m21 = yz - wx;
   mat.m31 = 0;
   mat.m02 = xz - wy;
   mat.m12 = yz + wx;
   mat.m22 = wSq - xSq - ySq + zSq;
   mat.m32 = 0;
   mat.m03 = 0;
   mat.m13 = 0;
   mat.m23 = 0;
   mat.m33 = 1;
   return mat;

You can just multiply this matrix by your camera matrix and it will give you what you want.  org.lwjgl.util.Quaternion has the method Quaternion.setFromAxisAngle() for constructing a quaternion from a vector and an orientation.  My guess is that you should be using that.
8  Java Game APIs & Engines / OpenGL Development / Re: Managing Multiple Shader Programs on: 2014-01-19 04:43:53
Thanks for your advice.  I see what you mean about juts sending in pass through data for info which isn't being used.  That could help out.  Right now I have the following shader programs: One for general static meshes. One for drawing billboards, the creation of which was chronicled in my previous thread.  One for drawing the ground which gets special treatment since it can have shadows drawn on it.  One for skinned meshes (which I am working on now).  And one specifically for drawing text and the HUD info, which I think could combine with the billboard shader if I wanted to.  I'm not sure how many shaders I'm going to want to use so far, but I am planning on using them for some other specialized effects.  All in all it seems like the first option is a little too messy once you get more than 2 or 3 shaders going, but perhaps there are ways I can simplify things and use fewer...

Thanks a bunch for your quick response!  Grin
9  Java Game APIs & Engines / OpenGL Development / Managing Multiple Shader Programs on: 2014-01-19 01:04:26
Hey all,

I'm getting to the point where I'm starting to have several shaders (so far up to five) and am wondering how some of you start managing these.  So far my system is less than elegant and I'm sure there is a cleaner, more OO way of doing this.  Here are a few of my ideas:

1) My current system is to have one Shader class which takes source code Strings as inputs in the constructor. I then have the main game class take care of compiling, binding, passing uniforms, and everything else.  This is working fine for a small number of shaders but I can see it'll be way too disorganized later.

2) Have the Drawable objects (Drawable is an interface) themselves keep track of which shader to use when being drawn.  This sounds like a nice solution but it'll mean that each drawable object will need references to things like the current camera and projective matrix which doesn't seem like good object oriented practice.

3) Have a ShaderManager object which takes care of uniforms and binding and have a public static method getShader() or something which drawable gives drawable objects access.  Again, doesn't seem like very good OO practice since only Drawable classes actually need access to these shaders.  I could pass a reference to the ShaderManager to each Drawable but I don't really like that either.

4) Something else???

Any advice would be greatly appreciated!  Looking forward to a good discussion.  Smiley

10  Game Development / Game Mechanics / Re: Rotate camera around origin problem on: 2014-01-18 16:23:03
It sounds like you are running into gimbal lock, which this video does a good job of explaining:

The best solution to this is to represent your rotations by quaternions instead of Euler angles.  The math for those can be a little confusing at first, but once you get the hang of it you'll really like them.
11  Game Development / Newbie & Debugging Questions / Re: GLSL - make effect only on one texture on: 2014-01-18 00:54:24
Changing the current shader program isn't something you want to do 10,000 times per frame, but a few times is fine  Grin
12  Discussions / General Discussions / Re: Dealing with billboards and Z buffers on: 2014-01-17 00:21:01
As promised, here is the code for the proper billboard shader:

////// VERTEX SHADER //////

#version 330

in vec3 position;
in vec2 texCoord;
in vec2 size;

out vec2 texCoord0;
out vec2 size0;

void main() {
   gl_Position = vec4(position, 1);
   size0 = size;
   texCoord0 = texCoord;

////// GEOMETRY SHADER //////

#version 330

layout (points) in;
layout (triangle_strip, max_vertices = 4) out;

uniform mat4 projectionMatrix;
uniform mat4 cameraMatrix;
uniform float scale = 6.5;

in vec2 texCoord0[];
in vec2 size0[];

out vec2 texCoord1;
out float depth1;

void main() {
   mat4 modelMatrix = mat4(1);
   modelMatrix[3] = gl_in[0].gl_Position;
   modelMatrix[0][0] = scale * size0[0].x;
   modelMatrix[1][1] = scale * size0[0].y;
   mat4 nonBillboardMatrix = projectionMatrix * cameraMatrix * modelMatrix;

   modelMatrix[3] = cameraMatrix * gl_in[0].gl_Position;
   mat4 billboardMatrix = projectionMatrix * modelMatrix;  

   // Emmit the verts

    gl_Position = billboardMatrix * vec4(-0.5, 0.0, 0.0, 1.0);
    texCoord1 = vec2(texCoord0[0].x, texCoord0[0].y + size0[0].y);
    depth1 = ((gl_DepthRange.diff * nonBillboardMatrix[3][2]  / nonBillboardMatrix[3][3])
             + gl_DepthRange.near + gl_DepthRange.far) / 2.0;
    gl_Position = billboardMatrix * vec4(0.5, 0.0, 0.0, 1.0);
    texCoord1 = texCoord0[0] + size0[0];

    gl_Position = billboardMatrix * vec4(-0.5, 1, 0.0, 1.0);
    texCoord1 = texCoord0[0];
    depth1 = ((gl_DepthRange.diff * (nonBillboardMatrix[1][2] + nonBillboardMatrix[3][2])
       / (nonBillboardMatrix[1][3] + nonBillboardMatrix[3][3]))
       + gl_DepthRange.near + gl_DepthRange.far) / 2.0;

    gl_Position = billboardMatrix * vec4(0.5, 1, 0.0, 1.0);
    texCoord1 = vec2(texCoord0[0].x + size0[0].x, texCoord0[0].y);


////// FRAGMENT SHADER //////

#version 330

in vec2 texCoord1;
in float depth1;

uniform sampler2D sampler;

void main() {
   vec4 color = texture(sampler, texCoord1);

   gl_FragColor = color;
   gl_FragDepth = depth1;
   if(color.a != 1)

As I said above, this still doesn't work perfectly but it's good enough for my needs and much better than what I had before!
13  Discussions / General Discussions / Re: Finding musicians? on: 2014-01-16 18:06:26
I actually have a degree in music composition and would be glad to help out.  Let me know if you are interested.
14  Discussions / General Discussions / Re: Dealing with billboards and Z buffers on: 2014-01-16 18:01:10
I've got it working by using the technique discussed above.  It still isn't perfect, but it's good enough.   There is still a bit of undesirable behavior when sprites are too close to 3D objects or if the camera is at some extreme angle, but overall it works well enough for my purposes.  As another poster said above, I can keep this from happening by implementing collision detection.

Thanks for all the help.  I'm going to clean up the code and then I'll post it in case anyone else wanted to see it.
15  Discussions / General Discussions / Re: Dealing with billboards and Z buffers on: 2014-01-15 18:57:13
Thanks for the tip about outputting depth in the fragment shader.  That will definitely help.  After looking at my own diagram again I believe I am actually doing the computation wrong.  You are correct, I want the depth value from before the sprite was billboarded.  This actually makes the most sense because the desired depth value should still come from a point the sprites's height away from it's base.  The value I was using was too large which is why his head was sticking out of the box when he was standing behind it.  Here is an image which I think shows what you are saying:

So yes, the vectors need to be normalized.  Fortunately this is easy to fix, as long as you remember to unlinearize in the fragment shader (is "unlinearize" a word???).  I have a habit of writing up replies in this thread before trying to program them so it could be that I'm jumping the gun once again.  Hopefully not! 

Also, you may be interested in the way that the billboarding happens.  Since all the modelview matrix for a billboard does is translate and "unrotate" you can simplify the calculation quite a bit.  Here is basically what the geometry shader does.  I'm using block matrix notation here so if it's a little confusing let me know:

From there I just generate 4 verticies at (-0.5, 0, 0), (0.5, 0, 0), (-0.5, 1, 0), and (0.5, 1, 0) and multiply those by the matrix A.
This puts the sprite exactly where I want it (at location 's' in world coordinates) with no rotation!

P.S. I don't feel patronized but you should know that I am working on a PhD in mathematics so I do understand the notation pretty well. Smiley Still, you never know who you're talking to on the internet so there's no reason you would know that. Grin  As always, it's nice to have a person to bounce ideas off. (It says that this thread has been read over 600 times at this point... anyone else want to chime in?)
16  Discussions / General Discussions / Re: Dealing with billboards and Z buffers on: 2014-01-14 17:39:13
Thanks so much for helping me talk through all this.  Here is a diagram that I think will explain what I'm trying to do:

I wouldn't worry about the geometry shader.  Basically all it does is take a vertex and emit a quad to draw the sprite on.  The main reason this is simpler is because it doesn't need to care about the camera's rotation component since it just undoes it anyway, so I don't have to pass that along the pipeline.  Aside from a simple pass-through shader I think it's one of the simpler ones to implement.
17  Game Development / Newbie & Debugging Questions / Re: [Solved] count up to 16 with one digit on: 2014-01-13 22:26:29

If you want something a little more interesting you should look into alternate numerical systems.  For example, the ancient Mayans had a cool counting system based on base 60(!) and writing a translator could be a lot of fun actually.  You could change the symbols to be more "alieny" as well.  I like the idea of aliens having their own language in general, I think that's pretty cool.

Good luck with your game.
18  Game Development / Newbie & Debugging Questions / Re: Hello! I'm New and ready to start! on: 2014-01-13 20:30:28
You sound excited!  My advice is to start with something small that you can complete in a few days.  If you've never programmed a game before I'd start by creating a clone of pong or something similar so you can learn the basics.  I know it's not exciting, but believe me when you finish your first game you'll be very proud!  Grin  As you get more experienced you'll want to take on larger projects.  Try to take baby steps, making each game you work on slightly more advanced than the last one.

As far as your 2D / 3D question goes I think it just depends on how much math you know.  In order to really understand how 3D works you probably need at least a basic understanding of vector math (a linear algebra class would help a lot).  If you haven't taken that level of math yet I'd start with 2D then.  It's a lot less complicated and you can still create some very fun and engaging games!
19  Discussions / General Discussions / Re: Dealing with billboards and Z buffers on: 2014-01-13 20:19:39
Ehh more complications.  I migrated all my sprite code over to a geometry shader which simplified things quite a bit but I'm, still unable to actually get the z buffers correct.  At first I was getting very weird results but I realized that this was likely due the fact that I was linearly interpolating depth values which is a nonlinear space.  So now I'm trying the following, but it seems like I'm still not quite getting what I want:

1) Find the cosine of the angle of rotation between the sprites Y-axis and world Y-axis.  I pass in the camera's rotation matirx and do the following calculation:

dot(Ry, y)

Since the sprite is rotated to always face perfectly forward, y= (0, 1, 0) and this dot product is actually mostly zeros so the result is just R[1][1].

2) Get the sine instead.  That's easy: sin(t) = sqrt(1 - cos^2(t)).

3) Set the desired depth to be the normal depth at the sprite bottom, and + sin(t) at the top (since the hypotenuse is just the sprite's height and right now they are all height 1).  Then just pass this over to the fragment shader who will happily interpolate. Inside the fragment shader I redo the perspective divide so as to not mess up the non-linearity. (I forgot to do this at first and was confused for a good while).

Unfortunately I'm still not getting results I want.  Now the sprites top sticks out from under things it shouldn't.  I know why this is but I'm not sure what the solution ought to be.
20  Game Development / Newbie & Debugging Questions / Re: count up to 16 with one digit on: 2014-01-13 19:55:42
No, 170 is correct, 100 is incorrect since you're working in base 17.

A = 10, the 0 means carry 17 over.

17 * 10 = 170 not 100.

Here's how you work it out:

17^3       17^2       17        1
0             0            A (10)   0

17^3 x 0 + 17^2 x 0 + 17 x 10 + 1x0 = 170, not 100.

Similarly in base 10 (decimal):

10^3       10^2       10        1
0             0            10        0

10^3 x 0 + 10^2 x 0 + 10x10 + 1x0 = 100

This is correct.  You are not in hexidecimal since you have 17 symbols (0-9 and A-G) representing values.  That means that each place value represents a power of 17.  In regular old decimal we call these the 1's place, 10's place, 100's place, etc., which you learned about in school.  So your alien numerical system works on base 17 so you have the 1's place, 17's place, 289's place (17*17), 4913's place (17*17*17), and so on. 
21  Game Development / Newbie & Debugging Questions / Re: count up to 16 with one digit on: 2014-01-13 19:43:57
This isn't too hard, you just have to convert from base 10 to base 17 or vice versa (it's base 17 since you have 17 possible digits).  How you do this is successively divide your number by whatever base you are converting to and keep track of the remainders.

This is untested so it might have a typo or something

public static String convertToBase(int input, int base) {

 String output = "";
 int value = input;

 while(value > 0)
   remainder = value % base;
   output = getDigit(value).concat(output);  // have getDigit return a string containing the desired digit for this value and tack it on the front
   value /= base;

 return output;

In your case, just call convertToBase(whateverNumebr, 17). That should work fine.  Converting from one base to another is a similar process.

EDIT: I didn't notice that you wanted it to work for negative values as well.  Just check if the integer is negative at the beginning of the method and multiply by -1.  Then put a final "-" string at the front of output before you return.

2nd EDIT: Oh wow, I didn't realize that the Integer.parseInt() method could do this for you.  I agree with those above, just use that instead of writing your own method.  Still, it's nice to know how it works!
22  Game Development / Game Mechanics / Re: Loading and storing card images on: 2014-01-13 04:32:18
I would just load a large texture map at first and worry about optimizations if it becomes an issue.  Like you said, you can load needed textures while at that time and it doesn't really matter how long it takes.  I'm sure someone else here probably has more useful info for you though Smiley
23  Discussions / General Discussions / Re: Dealing with billboards and Z buffers on: 2014-01-11 22:25:58
I am using two different shaders for sprites and general geometry.  The reason I cannot simply pass a uniform float to the fragment shader is because this will not have the desired effect.  As you can see in the video above, when the camera is rotated about the x-axis the guy start to intersect with the cubes when it stands too close in front of it.  The more rotation happens, the worse the problem is.  Since sprites are rotated to face the camera directly, they already have constant z coordinates in clip space.  Another way to think about this is that the sprites themselves are not rotated at all, only the rest of the world is.  So the cube, which is suppose to be facing "up" is actually tilted forward.  This means that the values stored to the depth buffer from the cube are increasing as you move up along the face.  In contrast, the sprites depth buffers values are constant, so at some point the cube will be in front of the cube.  Passing one uniform constant or another won't change the fact the the problem is arising from the cubes slant, not the sprites.

I hope that clears up the issue.  I myself was also confused because I was thinking that the sprite was being rotated (which it is in world space, but not in camera space).  The only solution I can think of right now is to linearly interpolate between two desired depth buffer values (based on the tangent of the angle of rotation about the horizontal), one at the base and another at the top.  Luckily the fragment shader can do this for me so I don't think it will be too difficult to implement.  If I get something working I'll update this thread.
24  Discussions / General Discussions / Re: Dealing with billboards and Z buffers on: 2014-01-11 01:02:45
The trouble is that I don't want the sprite to always show up if he is behind something.  The issue becomes worse if the camera is rotated downward.  I made a short video to show what I am talking about.

As you can see, it looks like he should be in front of the cubes, but sometimes he isn't.  I think what I need to do is somehow linearly move the depth from the bottom of the sprite to the top, based somehow on the X rotation of the viewing angle.  I'll keep working away on it and update this thread if I have any problems.

On the plus side, I do have the camera rotations working for the character, which is fun.
25  Discussions / General Discussions / Re: Dealing with billboards and Z buffers on: 2014-01-10 21:33:28
Thanks for the advice.  I don't think that will work for me since I am trying to allow the character to move behind 3D objects.  Think of it as being like in the game Paper Mario where the world is 3D but the people are 2D.

The above approach where I set the z buffer directly from a uniform isn't going to work. Doing this gives every fragment the same value in the z buffer, which effectively does nothing at all since the quads were rotated to be flat with the camera anyway.  I've tried changing the point where the buffer is calculated from to be slightly ahead of where the sprite is drawn but haven't been able to find satisfactory results.  I'll post in this thread again if I am able to solve this problem.
26  Discussions / General Discussions / Re: Dealing with billboards and Z buffers on: 2014-01-10 16:55:34
Thanks for the help.  This is what I was planning on doing, but I wasn't sure if there was a better way.

The problem is certainly due to the fact that the character is facing the camera.
But the character should stay perpendicular to ground,
so I think you should try to rotate the character only on the Y axis and cancel rotations on X and Z axis.

I had tried this as well but it made the characters just look like they were squished.  It seems that as long as no X or Z rotations happen once the scene starts the illusion works and it looks like the guy is standing properly.  At least to me, I'll see what others think.
27  Discussions / General Discussions / [Solved (mostly)] Dealing with billboards and Z buffers on: 2014-01-10 04:22:04
I've been playing around with some things trying to maybe get a 3D engine made.  Not really a game yet, just messing around.  Right now I have a small map and a guy who walks around.  The map is full 3D but the character is a 2D sprite which is rotated to face the camera.  Unfortunately, this is giving a weird result which you can see here (try to ignore the awful awful art at this time, I am no artist):

The only thing I can think to do about this to pass some uniform to the fragment shader to force the Z buffer to be something else, but I'm not exactly sure how to do this or if it is the best solution.  Anyone have any experience with this sort of thing? I'm mostly going this route because I don't know anything about 3D animation and it seemed a little easier to get started with 2D sprites for characters.
28  Game Development / Newbie & Debugging Questions / Re: lwjgl getTime and it's delta issue on: 2014-01-09 18:06:28
int delta = (int)(currentTime * lastFrame);

Here is your problem.  The delta should be the difference between the times, not the product.  In mathematics, the Greek letter delta is often used for differences because, well, it's like a D for difference  Wink
And the negatives are probably because (long * long) cast to int will often overflow.
I figured it was something like that.  To OP, hope this solved your issue.
29  Game Development / Newbie & Debugging Questions / Re: Limits of drawing BufferedImages? on: 2014-01-09 18:05:12
Take this advice with a grain of salt but I think the only way to continue using pure java and take advantage of hardware acceleration is to use the VolatileImage class, but as far as I know the use of this class is discouraged and I've personally never been able to get it to work.  Without that I think since Java2D runs entirely on the CPU you're not going to be able to do much better than what you are.  Are you using spritesheets? That might help a little.
30  Game Development / Newbie & Debugging Questions / Re: lwjgl getTime and it's delta issue on: 2014-01-07 17:42:14
int delta = (int)(currentTime * lastFrame);

Here is your problem.  The delta should be the difference between the times, not the product.  In mathematics, the Greek letter delta is often used for differences because, well, it's like a D for difference  Wink
Pages: [1] 2 3
nelsongames (17 views)
2018-04-24 18:15:36

nelsongames (13 views)
2018-04-24 18:14:32

ivj94 (587 views)
2018-03-24 14:47:39

ivj94 (50 views)
2018-03-24 14:46:31

ivj94 (400 views)
2018-03-24 14:43:53

Solater (64 views)
2018-03-17 05:04:08

nelsongames (110 views)
2018-03-05 17:56:34

Gornova (175 views)
2018-03-02 22:15:33

buddyBro (723 views)
2018-02-28 16:59:18

buddyBro (93 views)
2018-02-28 16:45:17
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!