Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (576)
games submitted by our members
Games in WIP (497)
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]
1  Game Development / Game Mechanics / Re: Raytracing - Tutorials? on: 2014-02-01 07:43:34
Thank you, and sorry for the late response.
I'll look into your link.  Cheesy
2  Game Development / Game Mechanics / Raytracing - Tutorials? on: 2014-01-28 22:57:51
Hey guys.
I don't know much about raytracing other than that it's a fairly complex technique though essential in modern game engines for advanced lighting and collision checking.
I would like to read up on raytracing in general but all the materials I found on the subject seems to be fairly advanced and I have a hard time studying them.
I would need rather simple, step-by-step explanation on the hows and whys because I hate to use something without understanding what's going on under the hood. Roll Eyes

If somebody can point me to a tutorial or a book where raytracing is well explained I would be very grateful. Cheesy
3  Game Development / Game Mechanics / Re: Font rendering with BMFont on: 2014-01-14 15:58:06
I can't find anything wrong in your code above, but I think this has to do with how you render the font. Characters that should be aligned with the baseline but ascend above it (t, f, l, any capital letter, etc) are rendered as though they're characters that descend below it (y, g, p, q, etc) and vice versa. So you just need to "flip" the y-offset for those characters. Hopefully this makes sense. Cheesy
Thank you, you got me started in the right way but that wasn't quite the solution.

So what the problem was that all the tutorials I found on the subject used (0,0) as their top-left coordinate (but they never really mentioned it), while (0,0) for me is my bottom-left coordinate so all I had to do is instead of rendering from the bottom to the top (BL, BR, UR, UL order) I'm now rendering from top to bottom (TL, BL, BR, TR (these are CCW orders btw)) and instead of adding height to the cursor position I negate it. It's a bit hard to explain, but you'll find a picture below from the result and the working source code, feel free to use it for your own projects if needed.

  Pointing

Source 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  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
package com.pandadev.ogame.fonts;

import java.nio.FloatBuffer;
import java.nio.ShortBuffer;

import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL15;
import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL30;
import org.lwjgl.util.vector.Matrix4f;
import org.lwjgl.util.vector.Vector2f;

import com.pandadev.ogame.MatrixStack;
import com.pandadev.ogame.textures.Texture;

public class FontText {
   public FontText(Font font, String text, Vector2f position){
      this.fontTexture = font.getTexture();
      //Generate text using the font information
     Vector2f cursor = new Vector2f(position);
      FontCharacter lastCharacter = null;
      char[] textCharacters = text.toCharArray();
      FloatBuffer vertexData = BufferUtils.createFloatBuffer(textCharacters.length*16);
      for(char textCharacter : textCharacters){
         //Convert the character from ASCII value to FontCharacter object
        FontCharacter character = font.getCharacter(Character.toString(textCharacter));
         if(character == null){
            character = font.getCharacter(Character.toString('?'));
         }
         Vector2f charPos = new Vector2f(cursor.x+character.getOffsetX(), cursor.y-character.getOffsetY());
         //Check and apply kerning if possible
        if(lastCharacter != null){
            FontKerning kerning = font.getKerning(lastCharacter.getId(), character.getId());
            if(kerning != null)
               charPos.x += kerning.getValue();
         }
         //Calculating vertices and uploading to the buffer
        float[] vertices = {
            charPos.x, charPos.y, //Vertex #0 - UL
           character.getTextureX(), character.getTextureY(), //TexCoord #0 - UL
           charPos.x, charPos.y-character.getHeight(), //Vertex #1 - BL
           character.getTextureX(), character.getTextureEndY(), //TexCoord #1 - BL
           charPos.x+character.getWidth(), charPos.y-character.getHeight(), //Vertex #2 - BR
           character.getTextureEndX(), character.getTextureEndY(), //TexCoord #2 - BR
           charPos.x+character.getWidth(), charPos.y, //Vertex #3 - UR
           character.getTextureEndX(), character.getTextureY() //TexCoord #3 - UR
        };
         vertexData.put(vertices);
         cursor.x += character.getAdvanceX();
         lastCharacter = character;
      }
      //Generate indices
     this.index_count = textCharacters.length*6;
      ShortBuffer indexData = BufferUtils.createShortBuffer(index_count);
      short counter = 0;
      for(int i = 0; i < textCharacters.length; i++){
         short[] indices = {
            counter++, counter++, counter++,
            ((short)(counter-3)), ((short)(counter-1)), counter++
         };
         indexData.put(indices);
      }
      vertexData.flip();
      indexData.flip();
      //Upload data to the GPU
     this.vao = GL30.glGenVertexArrays();
      this.vbo = GL15.glGenBuffers();
      this.ibo = GL15.glGenBuffers();
      GL30.glBindVertexArray(vao);
         GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
         GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertexData, GL15.GL_STATIC_DRAW);
         GL20.glEnableVertexAttribArray(0);
         GL20.glEnableVertexAttribArray(1);
         GL20.glVertexAttribPointer(0, 2, GL11.GL_FLOAT, false, 16, 0L);
         GL20.glVertexAttribPointer(1, 2, GL11.GL_FLOAT, false, 16, 8L);
         GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ibo);
         GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indexData, GL15.GL_STATIC_DRAW);
      GL30.glBindVertexArray(0);
   }
   private final int vao;
   private final int vbo, ibo;
   private final int index_count;
   private final Matrix4f textureMatrix = new Matrix4f();
   private final Texture fontTexture;
   
   public Texture getFontTexture(){
      return fontTexture;
   }
   
   public void render(){
      MatrixStack.getTextureMatrix().load(textureMatrix);
      fontTexture.bind();
      GL30.glBindVertexArray(vao);
         GL11.glDrawElements(GL11.GL_TRIANGLES, index_count, GL11.GL_UNSIGNED_SHORT, 0L);
      GL30.glBindVertexArray(0);
      fontTexture.unbind();
   }
   
   public void destroy(){
      GL30.glDeleteVertexArrays(vao);
      GL15.glDeleteBuffers(vbo);
      GL15.glDeleteBuffers(ibo);
   }
   
}


I will probably write a complete tutorial on the subject soon, so those who don't know how to do this or don't understand it, stay tuned. Wink
4  Game Development / Game Mechanics / Font rendering with BMFont on: 2014-01-14 12:24:31
Hey guys. I'm trying to use BMFont to render some bitmap fonts with my engine and it almost works fine, however, I got stuck with a minor issue that I don't know how to overcome:

 Pointing

As you can see some of the fonts are in line but some of them are not.
I know for a fact that this has to do something with the characters'  Y offset, however, if I don't add that value to my cursor position then 90% of the characters will be in line but some characters such as y, g, and p (so basically those that would need minus offsetting) will be "in line" too, so their descender won't be placed lower.
I don't know what I'm messing up so please, if someone has experience with parsing and rendering BMFont bitmaps help me out here. Smiley

Here's my source code (I can provide the other classes as well, however I think this is the only important part):
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  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
package com.pandadev.ogame.fonts;

import java.nio.FloatBuffer;
import java.nio.ShortBuffer;

import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL15;
import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL30;
import org.lwjgl.util.vector.Matrix4f;
import org.lwjgl.util.vector.Vector2f;

import com.pandadev.ogame.MatrixStack;
import com.pandadev.ogame.textures.Texture;

public class FontText {
   public FontText(Font font, String text, Vector2f position){
      this.fontTexture = font.getTexture();
      //Generate text using the font information
     Vector2f cursor = new Vector2f(position);
      FontCharacter lastCharacter = null;
      char[] textCharacters = text.toCharArray();
      FloatBuffer vertexData = BufferUtils.createFloatBuffer(textCharacters.length*16);
      for(char textCharacter : textCharacters){
         //Convert the character from ASCII value to FontCharacter object
        FontCharacter character = font.getCharacter(Character.toString(textCharacter));
         if(character == null){
            character = font.getCharacter(Character.toString('?'));
         }
         Vector2f charPos = new Vector2f(cursor.x+character.getOffsetX(), cursor.y+character.getOffsetY());
         //Check and apply kerning if possible
        if(lastCharacter != null){
            FontKerning kerning = font.getKerning(lastCharacter.getId(), character.getId());
            if(kerning != null)
               charPos.x += kerning.getValue();
         }
         //Calculating vertices and uploading to the buffer
        float[] vertices = {
            charPos.x, charPos.y, //Vertex #0
           character.getTextureX(), character.getTextureEndY(), //TexCoord #0
           charPos.x+character.getWidth(), charPos.y, //Vertex #1
           character.getTextureEndX(), character.getTextureEndY(), //TexCoord #1
           charPos.x+character.getWidth(), charPos.y+character.getHeight(), //Vertex #2
           character.getTextureEndX(), character.getTextureY(), //TexCoord #2
           charPos.x, charPos.y+character.getHeight(),  //Vertex #3
           character.getTextureX(), character.getTextureY() //TexCoord #3
        };
         vertexData.put(vertices);
         cursor.x += character.getAdvanceX();
         lastCharacter = character;
      }
      //Generate indices
     this.index_count = textCharacters.length*6;
      ShortBuffer indexData = BufferUtils.createShortBuffer(index_count);
      short counter = 0;
      for(int i = 0; i < textCharacters.length; i++){
         short[] indices = {
            counter++, counter++, counter++,
            ((short)(counter-3)), ((short)(counter-1)), counter++
         };
         indexData.put(indices);
      }
      vertexData.flip();
      indexData.flip();
      //Upload data to the GPU
     this.vao = GL30.glGenVertexArrays();
      this.vbo = GL15.glGenBuffers();
      this.ibo = GL15.glGenBuffers();
      GL30.glBindVertexArray(vao);
         GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
         GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertexData, GL15.GL_STATIC_DRAW);
         GL20.glEnableVertexAttribArray(0);
         GL20.glEnableVertexAttribArray(1);
         GL20.glVertexAttribPointer(0, 2, GL11.GL_FLOAT, false, 16, 0L);
         GL20.glVertexAttribPointer(1, 2, GL11.GL_FLOAT, false, 16, 8L);
         GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ibo);
         GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indexData, GL15.GL_STATIC_DRAW);
      GL30.glBindVertexArray(0);
   }
   private final int vao;
   private final int vbo, ibo;
   private final int index_count;
   private final Matrix4f textureMatrix = new Matrix4f();
   private final Texture fontTexture;
   
   public Texture getFontTexture(){
      return fontTexture;
   }
   
   public void render(){
      MatrixStack.getTextureMatrix().load(textureMatrix);
      fontTexture.bind();
      GL30.glBindVertexArray(vao);
         GL11.glDrawElements(GL11.GL_TRIANGLES, index_count, GL11.GL_UNSIGNED_SHORT, 0L);
      GL30.glBindVertexArray(0);
      fontTexture.unbind();
   }
   
   public void destroy(){
      GL30.glDeleteVertexArrays(vao);
      GL15.glDeleteBuffers(vbo);
      GL15.glDeleteBuffers(ibo);
   }
   
}
5  Java Game APIs & Engines / OpenGL Development / Re: Questions about VBOs / IBOs on: 2014-01-05 22:35:08
Since DirectX and OpenGL is so much more different and because you have so many questions I highly suggest reading an up-to-date book about OpenGL.
Sadly, they're pretty hard to get but from what I hear OpenGL Superbible's 6th edition is quite good. Also OpenGL 4.0 Shading Language Cookbook is a great piece, however, they're quite expensive. Cry
Could you explain what do you mean by "blocking calls"?
I don't know how exactly
glMapBuffer()
works so I can't help you with that one.
OpenGL contexts are automatically double buffered and you're always drawing to the back buffer (from default). After you're done with your frame you can swap the buffers (LWJGL automatically does this for you with
Display.update()
) so the user will see the rendered frame in the front buffer, and you can work on the back buffer that is currently filled with the frame before (that's why you have to clear the color/depth/stencil buffers so you clear those from the current back buffer).
6  Java Game APIs & Engines / OpenGL Development / Re: OpenGL Questions on: 2013-12-29 18:10:19
Well, it may sound harsh but try to think before you ask a question.
Last time when you was asking about the game design implementations of shaders we answered your question: They're used for everything.
And yes, "everything" includes everything from a simple cube to real time shadows and extreme lighting effects.
You can ask for examples but the answer is that they're everywhere. I've told you that the vertex shader is used for vertex position calculations and passing data to fragment shader, while the fragment shader tells OpenGL the color of the actual fragment it runs on.

glBindVertexArray(glGenVertexArrays()) simply binds an empty vertex array object, as far as I know this has no effect on rendering whatsoever, and you definitely should not get an error if it's missing (assuming that you do everything correctly). Also it's a bad practice since you should always store your generated object's id so later on you can delete it when you don't need it anymore, freeing up space VRAM.
Mod: Actually now I remember what vertex array objects do. As explained above by Danny02 they save the vertex attribute modifications and buffer bindings so if you use them all you have to do on rendering is to just bind the vertex array object and it'll set all the buffers and vertex attribute pointers for you again so all you have to do is just render using glDrawArrays(...) or glDrawElements(...).

The glVertexAttribPointer(...) in your example tells OpenGL that the data should be sent to attribute array 0 (so basically to location 0), that the attribute has 3 components (so it will become a vec3 in the shader), the type is float, the stride between the attribute in the buffer is 3<<2 (I don't really get it why do you do this, see my explanation on this parameter below) and that the data starts right on the first byte of the buffer.

You say that you understand every parameter in glVertexAttribPointer(...) and then you ask how does data gets passed to the shader, which clearly explains that you don't understand what glVertexAttribPointer(...) does.
Using glVertexAttribPointer(...) you can tell OpenGL what data it should send to the shader in what format.
One really important fact is that the vertex attribute pointer will always send data from the currently bidden array buffer.
The parameters are already explained here but I will try to rephrase them for you:
index - The index of the vertex attribute array (you will also have to enable it using glEnableVertexAttribArray(index))
size - The number of components that you're going to pass. Can be only 1, 2, 3 or 4 and OpenGL will automatically convert it to float (probably), vec2, vec3 or vec4.
normalized - If set to true OpenGL will normalize the value on access. Otherwise it should be set to false.
stride - The stride of the parameter IN BYTES. This is the most tricky value since not only the value is set in bytes but also you have to set the stride so that it will point from the first component to the next instance of this attribute. My explanation is probably crap because of my english skills but you should look it up once you start to use interleaved arrays (also remember that 1 float = 4 bytes). For now all you have to know that if you set it to 0 OpenGL will assume that the buffer is tightly packet and it can continuously read the data from it. TLDR: Set it to 0 for now, look it up later when you do more complex stuff.
offset - The offset before the attribute's first appearance in the buffer specified IN BYTES. This one's easier to explain than the stride: If your buffer looks like this [1, 2, 3, 4, 5, 6, ...] and you want OpenGL to read the buffer from number 4 you set the offset to 12 because that equals 3x4 so it'll skip the first 3 floats in the buffer. Also until you don't fill up your buffer with other stuff or you don't use interleaved arrays you shouldn't really worry about this and just set this to 0.

Some information I wrote here might not be 100% correct theoretically because I'm a hobbyist and not a professional (even though I'm planning to be one soon Grin), however most of the stuff should be correct. I know OpenGL can be hard to learn but never give up and you'll become good at it in no time. Smiley
7  Game Development / Game Mechanics / Re: 3D Camera with modern OpenGL on: 2013-12-25 15:14:29
I've added quite a few things to the camera, however I can't seem to figure out how should I move it on the y axis as well (the tutorial you linked moves the camera only on the Z and the X axis).
Of course I'm not talking about increasing the or decreasing the Y value of the camera but when I move forward or backward with the camera I would like my height to increase/decrease depending on my rotation on the X axis. I've tried adding something like this to the move method:

1  
position.y += amount*Math.sin(Math.toRadians(rotation.x+90*direction));

but it obviously doesn't work (I have no idea what I'm doing, damn you trigonometry *sigh*  Emo).
Anyone could help me out on getting this right and hopefully understanding the math behind it? Smiley

Edit: Okay, I've got it working, so far everything seems to be okay. If anyone is interested I did it this way:
1  
2  
if(direction == 1f)
   position.y += amount*Math.sin(Math.toRadians(rotation.x));

This way it only increases the Y value if you're moving on the Z axis (so if you just want to move sideways it won't be modified).
Still pretty much have no idea about the math behind it, I'm pretty much okay with vectors in 2D but when it comes to 3D it just almost always gets too complicated for me.
Probably will pick up a book on algebra and trigonometry. Stare
8  Java Game APIs & Engines / OpenGL Development / Re: OpenGL Questions on: 2013-12-25 09:59:06
Well I know that. I guess my original question wasn't too clear. Let me re-word it.
How would you split up the use of shaders in a game? Would you use a vertex shader for the camera and several fragment shaders for textures and visual effect etc.? What other things would you need a shader for in for example a simple 2D platformer?
I had a peek around the LibGDX source and noticed that it doesn't use the programmable pipeline. Why is this? Is it because the fixed function pipeline is good enough to use in 2D games? Are shaders and modern OpenGL functions that are part of the programmable pipeline only essential for content-rich 3D games?
I think you don't really understand what is a shader and what they're used for.

In modern OpenGL (3.1+ counts as modern IMO, because that's when all the deprecated stuff has became unsupported) you HAVE TO use shaders for getting anything to the screen. Pointing
There are different kinds of shaders (vertex, fragment (or sometimes called pixel), geometry) all serving their own purposes.
In the vertex shader you usually calculate vertex position (using the vertex attribute input multiplied with your own projection, view, model, etc. matrices) and pass over incoming attributes, e.g. normals to the fragment shader, while in the fragment shader you calculate a single fragment's (or pixel's, although I think this isn't really appropriate) color.

This is not a too complicated process once you understand what's going on under the hood, however, I really suggest you to pick up a book on modern OpenGL since immediate mode isn't really viable for rendering something else than just a few triangles, also it won't let you do any cool effects like lighting (other than the built-in crap that's practically useless) or anything else.
There are also a few good tutorials on the internet too, but honestly it's extremely hard to find decent tutorials on modern OpenGL (and by modern I mean something like GLSL 3.30 and definitely not GLSL 1.20).

You should check out Davedes's shader tutorials (he linked it in 1 or 2 posts above) because that's a good point to start from, even though that is not really modern either, it's way better than using immediate mode without any shaders. Wink
9  Java Game APIs & Engines / OpenGL Development / Re: OpenGL Questions on: 2013-12-24 22:04:11
Well, there are some weird parameters in OpenGL that you're likely to never use, although having options never hurts. Smiley

In modern OpenGL you fill up buffers just as you do now (glBufferData(...)/glBufferSubData(...)) but to assign data that goes to your shaders you have to use glVertexAttribPointer(...) and using that function you can set offsets and strides, letting you use a single buffer for multiple parameters. This means that you can store your vertex, normal and texture coordinate (and even more) data in a single buffer/VBO than you can render from that using your shaders.

To answer your question: You can use offsets in pointers to tell OpenGL where your attribute begins in the buffer but you shouldn't use this to "skip over" indices as you think right now.
If you want to skip over for example the first 5 indices you should render with glDrawArrays()'s first parameter set to 5.
I know it possibly sounds a bit overwhelming right now but if you have any questions just ask, after all that's what this topic is for. Roll Eyes
10  Game Development / Game Mechanics / Re: 3D Camera with modern OpenGL on: 2013-12-24 13:28:35
Thank you very much, using your link I've managed to get the camera working in just a few minutes. Cheesy
It seems like quite a basic camera, but now that at least I have something to go around with in my scene and observe the models I guess I'll have time to expand it later on. Cool
11  Game Development / Game Mechanics / 3D Camera with modern OpenGL on: 2013-12-23 21:53:26
Hey guys.
First of all merry christmas and happy holidays to everyone on the forum! Cheesy
Currently I'm trying to write my own engine on top of LWJGL to understand modern OpenGL better and get some basics down but I'm stuck at the part of writing a 3D camera.
The only decent tutorial I managed to find on the subject is this: http://games.greggman.com/game/webgl-3d-cameras/ (it's for WebGL but it's really easy to port it to LWJGL).
I've tried to make my own camera class based on the tutorial but it produces weird effects (turns models upside down and such) so I obviously mess up somewhere, the only question is where?! Huh

Here are my classes:
Camera.java - http://pastebin.com/LkfMR4NH
TestCamera.java (an instance of the camera class) - http://pastebin.com/gmP84PGQ
In the vertex shader the vertex position get's calculated as follows: projectionMatrix*viewMatrix*vec4(in_Position, 1.0);
, where in_Position is a vec3 of the vertex's local position. Currently I'm not using model matrices but I will implement that later.

If I understand the tutorial correctly to get the forward vector (or z axis vector) I have to subtract the target vector from the camera position vector, then normalise the result.
To get the right vector (or x axis) I have to take the cross product of my forward vector and a unit vector that points upwards on the Y axis.
To get the real up vector (or y axis) I have to take the cross product of the up and the right vector and voilá.
Of course to get the backward, left and down vectors I just have to negate the appropriate vectors.
After I did this all to apply the transformations I can just fill up a 4x4 matrix with the given data and use it as my view matrix.
However, as you can see in my code I do exactly this and it just doesn't seem to work.
Any help would be very much appreciated since I'm trying to solve this problem for quite a few hours now.
12  Games Center / Showcase / Re: Escape Copter (updated 8/21/2013) on: 2013-08-22 19:00:12
Okay, so after playing around with this for a while I have to say that this turned out really cool! Smiley
The gameplay feels smooth, it's simple yet challenging. Using minimal amount of colors really gives it a nice style.

However, there are some bugs what I've experienced:
  • The .exe file doesn't work (I'm using Windows 8, maybe that's the issue?), just starts it in the background and it's impossible to kill the process.
  • Right clicking on the game's context gives me a black screen and can't continue playing the game until I close it's window and restart it.
  • The helicopter's collision box isn't working properly, there were a few times when the tail/rotor totally hit the wall and nothing happened.
  • When colliding with a wall on low speed the helicopter doesn't break but adds a blueish box there. (Not sure if this is a correct behavior)
  • Sometimes when the helicopter breaks the game zooms out and you can see the end of the top and/or bottom walls. It is only a visual thing but it's kind of annoying. I suggest to either make the walls a bit thicker or to drop the zoom effect.

I hope you've had learned a lot from your project, keep up the good work! Cool
13  Java Game APIs & Engines / OpenGL Development / Re: [LWJGL Texture render order?] *solved* on: 2013-01-29 10:59:25
There's several OpenGL debugging functions out there, don't forget to put them in your main loop, so things like that won't occur.
14  Game Development / Newbie & Debugging Questions / Re: How do games like Hill Climb Racing do collision detection? on: 2013-01-09 23:20:12
Look up Box2D, it's a 2D physics engine, probably the best around.
I'm not sure about this because most of the time I use pure LWJGL, but I think that Slick2D comes with it and LibGDX also (which is great for android game development).
However, I'm sure that it wouldn't be too hard to implement it into a LWJGL engine.  Roll Eyes
Edit: And here you go: http://www.jbox2d.org/
If you aren't sure how to use it here's a cool video on it from "TheCodingUniverse".
<a href="http://www.youtube.com/v/ZKJC2cloIqc?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/ZKJC2cloIqc?version=3&amp;hl=en_US&amp;start=</a>
15  Java Game APIs & Engines / OpenGL Development / Re: 2D ray casting lighting problem on: 2013-01-09 21:58:23
A slightly more flexible attenuation would be this:
1  
Attenuation = 1.0 / (ConstantAtt + (LinearAtt * Distance) + (QuadraticAtt * Distance * Distance))


Described here (5.5.1) and implemented here.

Extending it to a spotlight effect should not be too tough, either:
http://glsl.heroku.com/e#5700.4

Smiley
I'll definietly try this out tomorrow, thanks for posting it!
16  Game Development / Newbie & Debugging Questions / Re: Maze Game Advice on: 2013-01-09 18:58:37
Hi.
Some quick answers to your questions:
1. Yes, it's a good idea to make your mazes tile based. It will be useful when you would like to generate random mazes.
2. You can do it by dozens of different ways, however here is a pretty primitive solution:
Refer numbers to your tiles so it'll be like:
0 = Nothing
1 = Wall
2 = Player
And to store these values create a multidimensional array (int[][] level = new level[100][100] <- Here's the code to create 100*100 level).
After this all you have to do on movement is to check if the position where you want to move is a wall or not, with something like this:
1  
2  
3  
4  
5  
6  
7  
int playerPosition_x = 10;
int playerPosition_y = 10;
if(Keys.Right.isPressed()){
   if(level[playerPosition_x+1][playerPosition_y] == 0){
      //You can move here because there's nothing
  }
}

Please keep in my that I don't know how you have to handle inputs on BlackBerry JDE so Keys.Right.isPressed() is just an example.
Also don't forget to check if playerPosition_x+1 (or whatever tile you want to move to) is out of your array's bounds. (e.g. level[101][100], this will throw an OutOfBoundException since our level in my example is only 100 by 100 and not 101 by 100).
If you didn't understand anything just let me know and I'll try to explain it.
Good luck with your project! Smiley
17  Java Game APIs & Engines / OpenGL Development / Re: 2D ray casting lighting problem on: 2013-01-09 18:38:52
Okay, so after some day I've come up with a solution for attenuation with a simple fragment shader. Cool
If anyone else thinking about creating 2D lighting check out my shader: http://glsl.heroku.com/e#5900.4
Also I have to mention that I'm really newbie when it comes to shaders, I've started to learn them 3 hours ago so I'm pretty sure this could be improved, however, it's seems like a nice starting point.  Roll Eyes
18  Java Game APIs & Engines / OpenGL Development / Re: 2D ray casting lighting problem on: 2013-01-05 21:53:54
I guess the best solution is:
float distanceToLight = [...];
float pseudoRadius = Math.sqrt(radius + radius);
float extrusion = pseudoRadius-distanceToLight;

Well, if I understand the code what you gave me correctly then this is exactly what I do right now:
I have a radius to light up, calculate the dark areas and fill them in with polygons.
My only problem is that as you can see on my second picture it's not perfect since the polygon doesn't have as much vertexes as my circle do, and even if it would work I wouldn't be really happy about the result (I kinda want that attenuation).
Maybe I've messed up something, here's my code (it's getting runned for every vertex as you can see):
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
public void render(){
   glColor4f(0.976f, 0.972f, 0.772f, 0.8f);
   glCircle3i(x, y, radius);
   glColor4f(0f, 0f, 0f, 1f);
   glBegin(GL_TRIANGLE_STRIP);
   {
      for(int i = 0; i < vertexes.size(); i++){
         Vector2f[] object_vertexes = vertexes.get(i);
         for(int n = 0; n < object_vertexes.length; n++){
            Vector2f p1 = new Vector2f(x+(debugWidth/2), y+(debugHeight/2));
            Vector2f p2 = object_vertexes[n];
            float distance = (float) Math.sqrt((Math.pow(p2.x-p1.x, 2) + Math.pow(p2.y-p1.y, 2)));
            float remaining = radius-distance;
            Vector2f extendedPoint = new Vector2f(p2.x+(p2.x-p1.x) / distance * remaining, p2.y+(p2.y-p1.y) / distance * remaining);
            glVertex2f(p2.x, p2.y);
            glVertex2f(extendedPoint.x, extendedPoint.y);
         }
      }
   }
   glEnd();
}
19  Java Game APIs & Engines / OpenGL Development / 2D ray casting lighting problem on: 2013-01-05 21:23:02
Hey guys, I'm lurking around for a while now but this is my first post, so big hello to you all! Smiley
I'm just getting started with OpenGL and game development so please bear with me guys.
So I've come to the point that I can create all the shapes what I want to, I can handle transformations, and know how to use textures.
I thought that the next step will be 2D lights and shadows but I just can't get it working.
I've read the articles and visited links featured on this forum about it, and I do understand that I should cast "rays" from my lighting spot to all the vertices and then mask away the non visible parts, my only problem is that I don't know how should I do that? Also I don't really understand how to make a lighting source which attenuates with distance.
My thoughts about that is that I just render multiple circles with different opacity, but this sounds like a horrible idea.
For my other problem (lighting and shadows) I've came up with my own crappy solution:
What I do is that I render a light yellow circle with the radius of the light source and low alpha value, then I go through my vertices stored in an ArrayList and check if they're in the radius of the circle and if so then I do extend the vector with "remaining" length (which is getting calculated like this: I calculate the distance between the center of the rendered circle and the vertex and and I substract my radius with it) and I create a vertex at the casted spot (the crossing point of my ray and the vertex) and at the end of the extended vector. I do this with all of the vertices (per object) so I get a black polygon at the end.  Roll Eyes
I know this is really bad solution, altough I've spent a lot of time to make it.
Here's a picture presentating my method (and it's fault when I move light source too close):






I would really appreciate any help.
Thank you all guys, have a nice day Wink
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (12 views)
2014-04-15 18:08:23

BurntPizza (11 views)
2014-04-15 03:46:01

UprightPath (24 views)
2014-04-14 17:39:50

UprightPath (10 views)
2014-04-14 17:35:47

Porlus (27 views)
2014-04-14 15:48:38

tom_mai78101 (49 views)
2014-04-10 04:04:31

BurntPizza (108 views)
2014-04-08 23:06:04

tom_mai78101 (208 views)
2014-04-05 13:34:39

trollwarrior1 (176 views)
2014-04-04 12:06:45

CJLetsGame (182 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
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!