Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (568)
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  Java Game APIs & Engines / OpenGL Development / Re: FBO depth texture not working properly on: 2012-05-07 14:38:32
It's a shame that a lot of computers doesn't support OpenGL 3+ yet. That's why im limiting myself to OpenGL 2 for now.

Anyway, here's a off-topic question. Are loops supported in GLSL 1.20? The shader doesn't work on my old computer (which supports glsl 1.2 and opengl 2.1). It compiles without any errors but everything is just black. If I remove the loop and just copy everything inside it a few times, it will work. 
2  Java Game APIs & Engines / OpenGL Development / Re: FBO depth texture not working properly on: 2012-05-07 14:00:36
I agree. Starting to use VBOs and writing my own shaders was the best decision ever. Not only is it easier to achieve what you want to, it also gives you a much better understanding of basicly everything related to graphics programming.
3  Java Game APIs & Engines / OpenGL Development / Re: FBO depth texture not working properly on: 2012-05-07 13:32:06
I finally managed to solve it! All I had to do was to disable textures when rendering the depth map.

Still not sure why. It worked when I did this:

1  
2  
3  
4  
5  
// Works
glBindTexture(GL_TEXTURE_2D, tex1)
object1.render();
object2.render();
...


But if I bound another texture it stopped working:

1  
2  
3  
4  
5  
6  
// Doesn't work
glBindTexture(GL_TEXTURE_2D, tex1)
object1.render();
glBindTexture(GL_TEXTURE_2D, tex2)
object2.render();
...


Really weird. Anyway, I'm really happy I finally got it working.

Also,

You might still need to at least update the projection matrix since you have a new aspect ratio. Frankly I´m at quite a loss here...

Thanks for this. I actually forgot to make a new projection matrix. Perhaps not a huge deal, but it probably would've given me some bugs to fix later on.

Now I gotta post some smileys to express my happiness:

 Grin Grin Smiley Cheesy Grin Cool Tongue Smiley Grin
4  Java Game APIs & Engines / OpenGL Development / Re: FBO depth texture not working properly on: 2012-05-06 09:46:32
Could definitly be a shader problem. Ill try to remove all unrelated code in my shaders and post them here later today.

The reason why im not changing to the lights matrix is because right now I'm rendering the depth texture from the cameras POV.
5  Java Game APIs & Engines / OpenGL Development / Re: FBO depth texture not working properly on: 2012-05-06 08:50:48
The depth texture is not bound while rendering to it. This is my depth map rendering method (simplified)

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
public void createDepthMap(Light light) {
     
   glBindFramebuffer(GL_FRAMEBUFFER, light.getShadowMapFBO());
     
   glClear(GL_DEPTH_BUFFER_BIT);
     
   glPushAttrib(GL_VIEWPORT_BIT);
   glViewport(0,0,Constants.SHADOW_MAP_WIDTH, Constants.SHADOW_MAP_HEIGHT);
   glColorMask(false, false, false, false);
   
   for (Renderable r : renderableEntities)
         r.render();
     
   glColorMask(true, true, true, true);
   glPopAttrib();
   glBindFramebuffer(GL_FRAMEBUFFER, 0);
     
   glActiveTexture(GL_TEXTURE7);
   glBindTexture(GL_TEXTURE_2D,light.getShadowMapTexture());
   glActiveTexture(GL_TEXTURE0);
   
}


Here's my FBO generation method if it makes any difference

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  
public void initFBO() {

      depthTexture = glGenTextures();
      glBindTexture(GL_TEXTURE_2D, depthTexture);
     
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     
     
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
      glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);
     
      glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, Constants.SHADOW_MAP_WIDTH, Constants.SHADOW_MAP_HEIGHT, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, (ByteBuffer)null);
     
      glBindTexture(GL_TEXTURE_2D, 0);
     
      fbo = glGenFramebuffers();
      glBindFramebuffer(GL_FRAMEBUFFER,fbo);
      glDrawBuffer(GL_NONE);
      glReadBuffer(GL_NONE);
     
      glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D, depthTexture, 0);
     
      int FBOstatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
        if(FBOstatus != GL_FRAMEBUFFER_COMPLETE)
           System.out.println("GL_FRAMEBUFFER_COMPLETE failed, CANNOT use FBO\n");

        glBindFramebuffer(GL_FRAMEBUFFER, 0);

   }
6  Java Game APIs & Engines / OpenGL Development / FBO depth texture not working properly on: 2012-05-05 21:32:22
So, im trying to implement shadow mapping into my game and I can't seem to render to the depth texture properly (which is attached to a FBO). I don't know what part of the code that causes this problem so I wont post code for now. Anyway, here's a screenshot from my game. It has nothing to do with the problem, I posted it so you could see how it looks like.



Anyway, so instead of rendering the actual textures, I rendered the depth map instead. This is the result:



Yeah, that's not how it should look like. There appears to be a lot of tiny point everywhere and if you look closley, you can see that theres a line where every edge of the triangle is. However, look at the quad to the right. The depthmap seems to be correct for that quad.

I increased the depth texture dimensions and it now looks like this:



More and smaller points, not very surprising. I'm completly lost now. It's probably something really simple, but I can't just figure out what it is. Oh, and by the way, the depth texture is not rendered from the lights POV, but the cameras. I did this to make it more simple.

Any ideas on why this could be happening?

Edit: It appears to work the way it should if the size of the depth texture is less than or equal to 32x32. This doesn't make me less confused though.

7  Game Development / Newbie & Debugging Questions / Re: Trying to make a TweenMovement component on: 2012-04-30 22:43:29
lol hi! Cheesy You're the nehifish I know, right!?

I can help you over skype or something, lol.
8  Java Game APIs & Engines / OpenGL Development / Re: Can't get GLSL per-pixel lighting to work. on: 2012-04-22 16:59:46
Quote
Your shader code works perfectly fine. Try to put a light very very close to the skeleton and you´ll see that the color really varies per pixel.

You're right, it does work the way it should! Oh wow, now I feel really stupid. I guess the light was just too far away to make the lighting vary pixel by pixel.

Quote
Are you using an index buffer to draw the skeleton or not? I think you´re creating unique vertices for each triangle, am I correct?

You are correct, but I smoothed the normals the way you suggested earlier, by adding the normal of all the vertices that has the same position and then normalizing them. However, there must be something wrong with the code that does that. Anyway, thanks for you help. You've been really helpful  Smiley
9  Java Game APIs & Engines / OpenGL Development / Re: Can't get GLSL per-pixel lighting to work. on: 2012-04-22 16:02:31
Point light.
10  Java Game APIs & Engines / OpenGL Development / Re: Can't get GLSL per-pixel lighting to work. on: 2012-04-22 14:23:02
I get what you're saying but I don't believe that's the problem. I think I managed to smooth the normals, but the problem is still there. Please verify that I've understood everything about the lighting calculations correctly.

Currently I take the dot product of the normal (which remains constant for every face) and the normalized distance vector from the pixel to the light source. Take a look at this image:



Every black block represents a pixel, the yellow circle the light source, every red line a normal, and every green line the vector from the light source to the pixel.

The distance vector from the light source to the pixel will be different for every pixel since it's calculated in the fragment shader. The normal will of course remain the same for every pixel. As seen in the image, the angle between the two vectors varies so taking the dot product of the two should give different values for different pixels, right? Why isnt this the case?  Huh
11  Java Game APIs & Engines / OpenGL Development / Can't get GLSL per-pixel lighting to work. on: 2012-04-22 01:14:16
I'm trying to implement per-pixel lighting with GLSL in my program and I just can't get it to work. Also, sorry for the long post.

Every face has the same color. This image of an ugly skull that I rendered with my shaders should explain the problem:



Here's my shaders. I removed everything unrelated.

Vertex shader

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  
#version 130

in vec3 inPosition;
in vec4 inColor;
in vec3 inNormal;

smooth out vec4 color;
smooth out vec3 normal;
smooth out vec3 position;

uniform mat4 perspectiveMatrix;
uniform mat4 cameraTransformationMatrix;
uniform mat4 modelTransformationMatrix;

uniform vec3 lightPos;

void main()
{

   normal = inNormal;
   
   position = inPosition;
   
   color = inColor;
   
   vec4 pos  = cameraTransformationMatrix * vec4(inPosition, 1);
   
    gl_Position = perspectiveMatrix * pos;
 
}


Fragment shader:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
#version 130

smooth in vec4 color;
smooth in vec3 normal;
smooth in vec3 position;

uniform vec3 lightPos;

void main()
{

   vec3 lightDir = normalize(lightPos - position);

   float diffuseLightIntensity = max(0,dot(normalize(normal),lightDir));

   vec4 fragcolor = vec4(diffuseLightIntensity * color.rgb,color.a);
   
   fragcolor.rgb += vec3(0.2,0.2,0.2);

    gl_FragColor = fragcolor;
}


I've been trying to figure out what could cause this to happen. I've tried to change gl_FragColor to different things. For example, gl_FragColor = vec4(lightDir,1) draws the skull with interpolated colors (check image below).



This shows that lightDir varies with every fragment. So that can't be the problem. Now, if i put gl_FragColor = vec4(normalize(normal),1) I get this:



Which is expected, since every face has the same normal. Now, this part is what confuses me.

float diffuseLightIntensity = max(0,dot(normalize(normal),lightDir));

I take the dot product of the normal and the direction of the light. The normal remains the same for every part of the face, while the lightDir is different for every fragment of the face. Taking the dot product should give me a different value for each fragment, since lightDir is different for each fragment. Am I correct? Either way, diffuseLightIntensity remains the same for every fragment of the face, which can be seen on the first image.

I'm probably just misunderstanding something. If I'm doing something really stupid that I should be able to fix myself, then sorry for wasting your time. But hopefully I shouldn't make myself look like a fool.  Tongue

Any help is appreciated.  Smiley
12  Game Development / Networking & Multiplayer / Re: Prediction? on: 2012-02-04 20:56:58
If by shooters you mean first person shooters, then Im pretty sure alot of them only use client/server. For example all games made with the Source Engine. Sorry if it seems like Im trying to disprove you or something. I've always thought most action games used client/server so when someone tells me the complete opposite I have the right to sceptical. Tongue

Edit:

Heres a link that I found interesting, it describes the networking that the source engine use:

https://developer.valvesoftware.com/wiki/Source_Multiplayer_Networking
13  Game Development / Networking & Multiplayer / Re: Prediction? on: 2012-02-04 17:42:50
... at the cost of throughput. For the lowest delay use UDP, a peer-to-peer model and send as little as possible. There's a reason all (yes, all) major shooters out there today use this.

I know I shouldn't really argue with you about this since my knowledge is low, but I'm pretty sure lots of major shooter games use the client/server model. I could be wrong though.

Either way, if you say I should use p2p, then I probably should. It going to be a pain to re-write all my network code though. :/
14  Game Development / Networking & Multiplayer / Re: Prediction? on: 2012-02-04 15:17:38
I did a little test application that does this a couple of weeks ago:
http://www.java-gaming.org/topics/client-side-prediction-and-delayed-interpolation/25446/view.html

Thanks, ill check that out.

- Are you using a server-client model or a peer-to-peer model?
 - Are you using TCP or UDP?

Server/Client model. Currently using UDP, which I believe is the best choise for this project since I want to reduce latency as much as possible. But like I said, my experience is limited. If some thinks using TCP instead would be better, then I can change.

15  Game Development / Networking & Multiplayer / Prediction? on: 2012-02-04 12:11:01
Hi everyone, first post here.

Im working on a top-down multiplayer shooter game. Right now im working on the network code (using kryonet). This is my first multiplayer project so my networking knowledge is limited.

The first version of the networking code consisted of the server sending a packet containing information about the world every frame. I quickly realised that sending 60 big packets every second to every player is too much, so i set a limit on how often the server would send packets. Now, since the clients were no longer getting an update every frame, the game started to lag and stutter. I solved this by adding interpolation and now the problem is gone. Well, except that now I have input delay to deal with.

If I get it right, I understand that I must implement client side prediction. I don't know how to do it thought, and thats why I made this thread. It would be much appriceated if you could explain how I should implement prediction.  Smiley
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.

Riven (10 views)
2014-10-02 14:36:20

Pippogeek (41 views)
2014-09-24 16:13:29

Pippogeek (32 views)
2014-09-24 16:12:22

Pippogeek (22 views)
2014-09-24 16:12:06

Grunnt (48 views)
2014-09-23 14:38:19

radar3301 (30 views)
2014-09-21 23:33:17

BurntPizza (65 views)
2014-09-21 02:42:18

BurntPizza (37 views)
2014-09-21 01:30:30

moogie (44 views)
2014-09-21 00:26:15

UprightPath (53 views)
2014-09-20 20:14:06
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!