Java-Gaming.org Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (595)
Games in Android Showcase (168)
games submitted by our members
Games in WIP (647)
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  Java Game APIs & Engines / OpenGL Development / Re: A good Game Loop on: 2015-03-21 23:50:52
First of all, thank you very very much!

Second, whats your TimeUtils.currentTime();?

I've tried both System.nanoTime and System.currentTimeMillis and it didnt work that well.
2  Java Game APIs & Engines / OpenGL Development / A good Game Loop on: 2015-03-21 08:59:17
Hello,

For over two years I've been using this game loop, but now, I need delta and I just found out that this game loop delta isn't that great.
I would like to ask you guys how to create a decent game loop with, updates happening 60 times or maybe 30 times per second and ticks once per second with delta.


Here is what I've been using.

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  
   public void run() {
      // Calling the initialize Method to setup our environment
      init();
      // Variables for the FPS counter
      long lastTime = System.nanoTime();
      double ns = 1000000000.0 / 60.0;
      long lastTimer = System.currentTimeMillis();
      int frames = 0;
      int updates = 0;
      int checking = 0;
      int sum = 0;
      int avg = 0;
      double delta = 0;
      while (running) {
         long now = System.nanoTime();
         delta += (now - lastTime) / ns;
         lastTime = now;
         if (delta >= 1) {
            // 60 times per second this is reached
            update(this.public_delta);
            updates++;
            delta--;
         }
         // Render as many times as u can
         render();
         frames++;
         Display.update();
         if (System.currentTimeMillis() - lastTimer > 1000) {
            lastTimer += 1000;
            // Once per second this is reached
            this.public_delta = delta;
            this.public_fps = frames;
            String title = GeneralSettings.fullname + " FPS: " + frames + " UPS: " + updates/* + " Delta: " + this.getDelta() */;
            if (GeneralSettings.useAverageFPS) title += " Average: " + avg;
            if (GeneralSettings.showLightFloat) {
               if (world != null) title += " Light: " + world.DAY_LIGHT;
            }
            Display.setTitle(title);
            if (GeneralSettings.useAverageFPS) {
               sum += frames;
               checking++;
               if (checking == GeneralSettings.ticksPerAverage) {
                  avg = (sum / checking);
                  checking = 0;
                  sum = 0;
               }
            }
            tick();
            updates = 0;
            frames = 0;
         }
         if (Display.isCloseRequested()) running = false;
         Display.sync(fps_lock);
      }
      // If the game is closed, cleanup!
      cleanup();
   }


The problem with my game loop is, if I lock the fps at 30 for example, the UPS will also be lock at 30.
Also my Delta sometimes is like 0.03 others like 500.0. It reaches very high numbers when the computer cannot reach the 60 UPS per second.


How could I fix this?

Thanks
Joaogl.
3  Games Center / Featured Games / Re: State of Fortune on: 2015-01-08 07:48:13
One more bug I think...


4  Games Center / Featured Games / Re: State of Fortune on: 2015-01-07 00:04:32
You're playing with low settings! By choice or is it an old computer? I thought you were getting a new one?

I have, but first I haven't changed the settings much yet.. only wanted to buy a land and plant something really quick Cheesy and I've reduced the settings just to run it smoothly Cheesy
5  Games Center / Featured Games / Re: State of Fortune on: 2015-01-06 21:01:23
Ok, I couldn't resist... I just played it for 20 min Cheesy


I found a bug though...




The transparent texture has some transparency issues....


Also, suggestions:
 - The player movement is still a bit wierd...
 - We should be able to buy another land without the minimum spacing between lands if we are buying right beside one of our terrains... it would be like an expand function..
 - We should be able to zoom even more on the map to help the positioning of smaller terrains or just be able to use the arrows for smaller position adjustments...


Still, Great job! it looks really cool Cheesy keep it up!
6  Games Center / Featured Games / Re: State of Fortune on: 2015-01-06 17:25:08
Mike, u problably already noticed that I havent tried the new version Smiley. I'll try it very soon, haven't tried it yet mostly due to the java 8 requirement...
Maybe at the end of this week I'm install the java 8 and the game...

But from the screenshots.. nice work it looks really good Cheesy
7  Java Game APIs & Engines / OpenGL Development / Re: LWJGL 2.9.2 on: 2014-12-29 19:17:24
@kappa, quick question, I've tried to use LWJGL3 but there seems to be a lot of different stuff... any tutorials?

I tryied to follow the guide on the LWJGL website but it was broken.. at least it didn't work...

Thanks,
Joao Lourenco
8  Java Game APIs & Engines / OpenGL Development / Re: LWJGL 2.9.2 on: 2014-12-29 13:59:46
And so starts a new one!
9  Games Center / Featured Games / Re: State of Fortune on: 2014-12-28 14:52:35
some new content.... nah! just put it online! we already got soo many new things... map included....
10  Games Center / Featured Games / Re: State of Fortune on: 2014-12-28 12:44:03
Yup, once more... I CAN'T WAIT FOR THE UPDATE!
11  Game Development / Newbie & Debugging Questions / Problem applying the textures with VBO (LWJGL) on: 2014-12-25 19:45:54


Hello,

I my game has a tiled based top to down view.
I've been using immediate rendering which I think might be slower...
Now that I'm woried about performance and I want to make everything fast and bug free before I move on, I want to make it better... My thoughts using VBO...

I'm not sure if this is the best Idea or the right one to use but as far as I know it is.. if not tell me please.

My code that doesn't work:
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  
public class QuadRender {

   protected int vao, vbo, vio, vto;

   protected float[] vertices;
   protected byte[] indices = new byte[] {
         0, 1, 2, //
         2, 3, 0 //
   };
   protected byte[] texCoords = new byte[] {
         0, 0, //
         1, 0, //
         1, 1, //
         1, 1, //
         0, 1, //
         0, 0 //
   };

   public QuadRender(int size) {
      GeneralSettings.quads.add(this);
      vertices = new float[] {
            0.0f, 0.0f, 0.0f, //
            size, 0.0f, 0.0f, //
            size, size, 0.0f, //
            0.0f, size, 0.0f //
      };
      compile();
   }

   protected void compile() {
      vao = glGenVertexArrays();
      glBindVertexArray(vao);
      {
         vbo = glGenBuffers();
         glBindBuffer(GL_ARRAY_BUFFER, vbo);
         {
            glBufferData(GL_ARRAY_BUFFER, Buffer.createFloatBuffer(vertices), GL_STATIC_DRAW);
            glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
         }
         glBindBuffer(GL_ARRAY_BUFFER, 0);

         vio = glGenBuffers();
         glBindBuffer(GL_ARRAY_BUFFER, vio);
         {
            glBufferData(GL_ARRAY_BUFFER, Buffer.createByteBuffer(indices), GL_STATIC_DRAW);
         }
         glBindBuffer(GL_ARRAY_BUFFER, 0);

         glDeleteBuffers(vto);

         vto = glGenBuffers();
         glBindBuffer(GL_ARRAY_BUFFER, vto);
         {
            glBufferData(GL_ARRAY_BUFFER, Buffer.createByteBuffer(texCoords), GL_STATIC_DRAW);
            glVertexAttribPointer(1, 3, GL_UNSIGNED_BYTE, false, 0, 1);
         }
         glBindBuffer(GL_ARRAY_BUFFER, 0);
      }
      glBindVertexArray(0);
   }

   public void render(int x, int y, int texture, Shader shade) {
      glTranslatef(x, y, 0);

      glActiveTexture(GL_TEXTURE0);
      glBindTexture(GL_TEXTURE_2D, texture);
      glUniform1i(glGetUniformLocation(shade.getShader(), "texture"), 0);

      glBindVertexArray(vao);
      glEnableVertexAttribArray(0);
      glEnableVertexAttribArray(1);
      {
         glBindBuffer(GL_ARRAY_BUFFER, vio);
         glVertexPointer(2, GL_FLOAT, 0, 0);

         glBindBuffer(GL_ARRAY_BUFFER, vto);
         glTexCoordPointer(2, GL_FLOAT, 0, 0);

         glDrawArrays(GL_QUADS, 0, 4);
      }
      glEnableVertexAttribArray(1);
      glEnableVertexAttribArray(0);
      glBindVertexArray(0);
      glTranslatef(-x, -y, 0);

      glBindTexture(GL_TEXTURE_2D, 0);
   }

}


My code that does work:

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  
public class QuadRender {

   public QuadRender(int size) {
      GeneralSettings.quads.add(this);
   }

   public void render(int x, int y, int texture, Shader shade) {
      glTranslatef(x, y, 0);
      glActiveTexture(GL_TEXTURE0);
      glBindTexture(GL_TEXTURE_2D, texture);
      glUniform1i(glGetUniformLocation(shade.getShader(), "texture"), 0);

      glBegin(GL_QUADS);
      {
         glTexCoord2f(0, 0);
         glVertex2f(0, 0);

         glTexCoord2f(0, 1);
         glVertex2f(0, 64);

         glTexCoord2f(1, 1);
         glVertex2f(64, 64);

         glTexCoord2f(1, 0);
         glVertex2f(64, 0);
      }
      glEnd();
      glBindTexture(GL_TEXTURE_2D, 0);
      glTranslatef(-x, -y, 0);
   }

}


With the code that works it looks like this:



With the code that doesn't work it looks like this:




PS: the wooden bit uses another render engine for now thats why its not affected by the changes.


What the problem on the textures?

Thanks, Joao Lourenco.
12  Java Game APIs & Engines / OpenGL Development / Re: Shaders issue on: 2014-12-23 13:41:56
A couple of changes I made once more...

- Removed the attenuation if.
- I now pass in a variable with the lights amount to avoid the for loop trying to work unexistent lights.

<a href="http://www.youtube.com/v/VLiyF5iZj5U?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/VLiyF5iZj5U?version=3&amp;hl=en_US&amp;start=</a>

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  
#version 330 compatibility
#define LIGHTS_COUNT 50

uniform sampler2D texture;
in vec2 texCoords;

uniform float dayLight;

uniform int lightAmount;

uniform vec2 lightPosition[LIGHTS_COUNT];
uniform vec3 lightColor[LIGHTS_COUNT];
uniform float lightIntensity[LIGHTS_COUNT];
uniform float lightType[LIGHTS_COUNT];
uniform float lightSize[LIGHTS_COUNT];
uniform float lightFacing[LIGHTS_COUNT];

void main() {      
   vec4 color = vec4(1.0, 1.0, 1.0, 1.0);
   vec4 tex = texture2D(texture, gl_TexCoord[0].st);
   color = tex;
     
   float alpha = 1.0;
   if (tex.x == 1.0 && tex.y == 0.0 && tex.z == 1.0) {
      alpha = 0.0;
   }
   
   vec4 result = vec4(color.xyz, alpha);
   color = result;  
   vec4 dcolor = vec4(result * vec4(dayLight, dayLight, dayLight, dayLight));  
   
   int num = 0;
   int changed = 0;        
   
   for (int i = 0; i < lightAmount; i++) {
      vec2 pos = lightPosition[i];
      if (pos.x == 0 && pos.y == 0) continue;
      vec3 col = lightColor[i];
      float ints = lightIntensity[i];
     
      float distance = length(pos - gl_FragCoord.xy);
      float attenuation = 1.0 / distance;
     
      float falloff = 50 - distance / 5.0f / ints;        
           
      if (lightType[i] == 1) {
         color *= vec4(attenuation, attenuation, attenuation, pow(attenuation, 3)) * vec4((col / distance * 15) * ints, 1.0) + 0.01;
     
         color /= (distance / (ints * falloff));
         
         changed = 1;
         num++;
      } else if (lightType[i] == 2) {
         float angle = degrees(acos((pos.x - gl_FragCoord.x) / distance));      
         if (pos.y < gl_FragCoord.y) angle = 360 - angle;
         
         float max = (lightFacing[i] + (lightSize[i] / 2));
         float min = (lightFacing[i] - (lightSize[i] / 2));  
         bool spec = false;
         
         if (max > 360) {
            max = max - 360;
            spec = true;
         }
         if ((lightFacing[i] - (lightSize[i] / 2)) < 0) {
            min = 360 - abs(lightFacing[i] - (lightSize[i] / 2));
            spec = true;
         }
   
         if ((angle >= min && angle <= max && !spec) || ((angle >= min || angle <= max) && spec)) {
            color *= vec4(attenuation, attenuation, attenuation, pow(attenuation, 3)) * vec4((col / distance * 15) * ints, 1.0) + 0.01;
         
            color /= (distance / (ints * falloff));
            changed = 1;
            num++;
         }
      }
   }
   
   if (changed == 1) color *= 30.0 * pow(166.0, float(num - 1)) + 1;
   else color = dcolor;
     
   gl_FragColor = min(result, max(dcolor, color));
}



I don't think I can make the Point light any better now... At least I don't have any Ideas for now...
The SpotLight in the other hand, has still a few adjustments to be done.. For some reason the shader only works for the first light that is passed in... I've confirmed in the java side that I'm passing in both lights.

If anyone knows why the shader is only processing one light please tell me...


Thank you,
João Lourenço.
13  Java Game APIs & Engines / OpenGL Development / Re: Shaders issue on: 2014-12-23 12:07:09
Thank you Kefwar, I've no idea why but that solved my darker shadow when it was day....

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  
#version 330 compatibility
#define LIGHTS_COUNT 50

uniform sampler2D texture;
in vec2 texCoords;

uniform float dayLight;

uniform vec2 lightPosition[LIGHTS_COUNT];
uniform vec3 lightColor[LIGHTS_COUNT];
uniform float lightIntensity[LIGHTS_COUNT];
uniform float lightType[LIGHTS_COUNT];
uniform float lightSize[LIGHTS_COUNT];
uniform float lightFacing[LIGHTS_COUNT];

void main() {      
   vec4 color = vec4(1.0, 1.0, 1.0, 1.0);
   vec4 tex = texture2D(texture, gl_TexCoord[0].st);
   color = tex;
     
   float alpha = 1.0;
   if (tex.x == 1.0 && tex.y == 0.0 && tex.z == 1.0) {
      alpha = 0.0;
   }
   
   vec4 result = vec4(color.xyz, alpha);
   color = result;
   
   vec4 dcolor = vec4(result * vec4(dayLight, dayLight, dayLight, dayLight));  
   
   int num = 0;
   int changed = 0;        
   
   for (int i = 0; i < LIGHTS_COUNT; i++) {
      vec2 pos = lightPosition[i];
      if (pos.x == 0 && pos.y == 0) continue;
      float distance = length(pos - gl_FragCoord.xy);
      vec3 col = lightColor[i];
      float ints = lightIntensity[i];
     
      float attenuation = 1.0 / distance;
     
      float falloff = 80;
      falloff -= distance / 25.0f / ints;        
           
      if (attenuation >= 0.010) {
         if (lightType[i] == 1) {
            color *= vec4(attenuation, attenuation, attenuation, pow(attenuation, 3)) * vec4((col / distance * 15) * ints, 1.0) + 0.01;
         
            color /= (distance / (ints * falloff));
           
            changed = 1;
            num++;
         } else if (lightType[i] == 2) {
            float angle = degrees(acos((pos.x - gl_FragCoord.x) / distance));      
            if (pos.y < gl_FragCoord.y) angle = 360 - angle;
           
            float max = (lightFacing[i] + (lightSize[i] / 2));
            float min = (lightFacing[i] - (lightSize[i] / 2));  
            bool spec = false;
           
            if (max > 360) {
               max = max - 360;
               spec = true;
            }
            if ((lightFacing[i] - (lightSize[i] / 2)) < 0) {
               min = 360 - abs(lightFacing[i] - (lightSize[i] / 2));
               spec = true;
            }
     
            if ((angle >= min && angle <= max && !spec) || ((angle >= min || angle <= max) && spec)) {
               color *= vec4(attenuation, attenuation, attenuation, pow(attenuation, 3)) * vec4((col / distance * 15) * ints, 1.0) + 0.01;
           
               color /= (distance / (ints * falloff));
               changed = 1;
               num++;
            }
         }
      }
   }
   if (changed == 1) color *= 30.0 * pow(166.0, float(num - 1)) + 1;
   else color = dcolor;
     
   gl_FragColor = min(result, max(dcolor, color));
}



Thank you,
João Lourenço.
14  Java Game APIs & Engines / OpenGL Development / Re: Shaders issue on: 2014-12-23 02:35:46
I've Changed a couple more things...

- Added a new light type which I'm not happy with yet... the effect looks different don't know why yet...
- Removed day variable, the dayLight * 2 is now performed on the java side.

<a href="http://www.youtube.com/v/ZuOhlqAsa6M?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/ZuOhlqAsa6M?version=3&amp;hl=en_US&amp;start=</a>

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  
#version 330 compatibility
#define LIGHTS_COUNT 50

uniform sampler2D texture;
in vec2 texCoords;

uniform float dayLight;

uniform vec2 lightPosition[LIGHTS_COUNT];
uniform vec3 lightColor[LIGHTS_COUNT];
uniform float lightIntensity[LIGHTS_COUNT];
uniform float lightType[LIGHTS_COUNT];
uniform float lightSize[LIGHTS_COUNT];
uniform float lightFacing[LIGHTS_COUNT];

void main() {      
   vec4 color = vec4(1.0, 1.0, 1.0, 1.0);
   vec4 tex = texture2D(texture, gl_TexCoord[0].st);
   color = tex;
     
   float alpha = 1.0;
   if (tex.x == 1.0 && tex.y == 0.0 && tex.z == 1.0) {
      alpha = 0.0;
   }
   
   vec4 result = vec4(color.xyz, alpha);
   color = result;
   
   vec4 dcolor = vec4(result * vec4(dayLight, dayLight, dayLight, dayLight));  
   
   int num = 0;
   int changed = 0;        
   
   for (int i = 0; i < LIGHTS_COUNT; i++) {
      vec2 pos = lightPosition[i];
      if (pos.x == 0 && pos.y == 0) continue;
      float distance = length(pos - gl_FragCoord.xy);
      vec3 col = lightColor[i];
      float ints = lightIntensity[i];
     
      float attenuation = 1.0 / distance;
     
      float falloff = 80;
      falloff -= distance / 25.0f / ints;        
           
      if (attenuation >= 0.010) {
         if (lightType[i] == 1) {
            color *= vec4(attenuation, attenuation, attenuation, pow(attenuation, 3)) * vec4((col / distance * 15) * ints, 1.0) + 0.01;
         
            color /= (distance / (ints * falloff));
           
            changed = 1;
            num++;
         } else if (lightType[i] == 2) {
            float angle = degrees(acos((pos.x - gl_FragCoord.x) / distance));      
            if (pos.y < gl_FragCoord.y) angle = 360 - angle;
           
            float max = (lightFacing[i] + (lightSize[i] / 2));
            float min = (lightFacing[i] - (lightSize[i] / 2));  
            bool spec = false;
           
            if (max > 360) {
               max = max - 360;
               spec = true;
            }
            if ((lightFacing[i] - (lightSize[i] / 2)) < 0) {
               min = 360 - abs(lightFacing[i] - (lightSize[i] / 2));
               spec = true;
            }
     
            if ((angle >= min && angle <= max && !spec) || ((angle >= min || angle <= max) && spec)) {
               color *= vec4(attenuation, attenuation, attenuation, pow(attenuation, 3)) * vec4((col / distance * 15) * ints, 1.0) + 0.01;
           
               color /= (distance / (ints * falloff));
               changed = 1;
               num++;
            }
         }
      }
   }
   if (changed == 1) color *= 30.0 * pow(166.0, float(num - 1)) + 1;
   else color = dcolor;
     
   if (min(dcolor, color) == color) color = dcolor;
   
   if (min(result, color) == color) gl_FragColor = color;
   else gl_FragColor = result;
}



And after this changes, I'm officially out of ideas to performance upgrades...
Tomorrow I'm going to try to make the lights look better... don't know how...
If you have any ideas please tell me.. this is my first attempt at making light stuff...


Thanks,
João Lourenço.
15  Java Game APIs & Engines / OpenGL Development / Re: Shaders issue on: 2014-12-23 01:31:13
So instead of sending the info if the light is on or off only send the lights that are on right? that makes sence...

I'm trying to learn how to make shaders and only now I'm starting to realize that every operation done on the shader is very heavy... and when I did that if, for example, it was like ... heee there is no problem to check if its on or off on the shader... but there is... and for that I must thank you all.. ur helping a lot with small things...


so new version of the 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  
#version 330 compatibility
#define LIGHTS_COUNT 50

uniform sampler2D texture;
in vec2 texCoords;

uniform float dayLight;

uniform vec2 lightPosition[LIGHTS_COUNT];
uniform vec3 lightColor[LIGHTS_COUNT];
uniform float lightIntensity[LIGHTS_COUNT];
uniform float lightType[LIGHTS_COUNT];
uniform float lightSize[LIGHTS_COUNT];
uniform float lightFacing[LIGHTS_COUNT];

void main() {      
   float day = dayLight * 2;
   vec4 color = vec4(1.0, 1.0, 1.0, 1.0);
   vec4 tex = texture2D(texture, gl_TexCoord[0].st);
   color = tex;
     
   float alpha = 1.0;
   if (tex.x == 1.0 && tex.y == 0.0 && tex.z == 1.0) {
      alpha = 0.0;
   }
   
   vec4 result = vec4(color.xyz, alpha);
   color = result;
   
   vec4 dcolor = vec4(result * vec4(day, day, day, day));  
   
   int num = 0;
   int changed = 0;        
   
   for (int i = 0; i < LIGHTS_COUNT; i++) {
      vec2 pos = lightPosition[i];
      if (pos.x == 0 && pos.y == 0) continue;
      float distance = length(pos - gl_FragCoord.xy);
      vec3 col = lightColor[i];
      float ints = lightIntensity[i];
     
      float attenuation = 1.0 / distance;
     
      float falloff = 80;
      falloff -= distance / 25.0f / ints;        
           
      if (attenuation >= 0.010) {
         color *= vec4(attenuation, attenuation, attenuation, pow(attenuation, 3)) * vec4((col / distance * 15) * ints, 1.0) + 0.01;
         
         color /= (distance / (ints * falloff));
           
         changed = 1;
         num++;        
      }
   }
   if (changed == 1) color *= 30.0 * pow(166.0, float(num - 1)) + 1;
   else color = dcolor;
     
   if (min(dcolor, color) == color) color = dcolor;
   
   if (min(result, color) == color) gl_FragColor = color;
   else gl_FragColor = result;
}




Thank you,
João Lourenço.
16  Java Game APIs & Engines / OpenGL Development / Re: Shaders issue on: 2014-12-22 21:17:22
Ok so first of all thank you for the awnser and I've changed a few things, I hope its better now...

- Now using the LIGHTS_COUNT.
- If statement on line 39 has been moved.
- The ocolor was the "Original Color" but I've removed it since I can use the result which is also the original color.
- Now on the operations instead of using new vectors I only use the dcolor vector created at the beginning..


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  
#version 330 compatibility
#define LIGHTS_COUNT 50

uniform sampler2D texture;
in vec2 texCoords;

uniform float dayLight;

uniform vec2 lightPosition[LIGHTS_COUNT];
uniform vec3 lightColor[LIGHTS_COUNT];
uniform float lightIntensity[LIGHTS_COUNT];
uniform float lightInUse[LIGHTS_COUNT];
uniform float lightType[LIGHTS_COUNT];
uniform float lightSize[LIGHTS_COUNT];
uniform float lightFacing[LIGHTS_COUNT];

void main() {      
   float day = dayLight * 2;
   vec4 color = vec4(1.0, 1.0, 1.0, 1.0);
   vec4 tex = texture2D(texture, gl_TexCoord[0].st);
   color = tex;
     
   float alpha = 1.0;
   if (tex.x == 1.0 && tex.y == 0.0 && tex.z == 1.0) {
      alpha = 0.0;
   }
   
   vec4 result = vec4(color.xyz, alpha);
   color = result;
   
   vec4 dcolor = vec4(result * vec4(day, day, day, day));  
   
   int num = 0;
   int changed = 0;        
   
   for (int i = 0; i < LIGHTS_COUNT; i++) {
      if (lightInUse[i] == 1) {  
         vec2 pos = lightPosition[i];
         if (pos.x == 0 && pos.y == 0) continue;
         float distance = length(pos - gl_FragCoord.xy);
         vec3 col = lightColor[i];
         float ints = lightIntensity[i];
         
         float attenuation = 1.0 / distance;
         
         float falloff = 80;
         falloff -= distance / 25.0f / ints;        
             
         if (attenuation >= 0.010) {
            color *= vec4(attenuation, attenuation, attenuation, pow(attenuation, 3)) * vec4((col / distance * 15) * ints, 1.0) + 0.01;
           
            color /= (distance / (ints * falloff));
               
            changed = 1;
            num++;
         }
           
      }
   }
   if (changed == 1) color *= 30.0 * pow(166.0, float(num - 1)) + 1;
   else color = dcolor;
     
   if (min(dcolor, color) == color) color = dcolor;
   
   if (min(result, color) == color) gl_FragColor = color;
   else gl_FragColor = result;
}
17  Games Center / Featured Games / Re: State of Fortune on: 2014-12-22 18:46:14
That looks great... As usual.... I'm looking forward for that new version....

Keep up the good work!



Thanks,
João Lourenço.
18  Discussions / General Discussions / Re: Does web development count as programming experience? on: 2014-12-21 22:37:26
@HeroesGraveDev: U'r right but it still requires some programming like skill
19  Discussions / General Discussions / Re: Does web development count as programming experience? on: 2014-12-21 22:32:07
Yes.. Programming experience is the experience you have Programming... If u program in HTML/PHP/CSS or whatever... u are programming... so yes, it counts...
20  Java Game APIs & Engines / OpenGL Development / Shaders issue on: 2014-12-21 20:40:30
Hello,

I'm trying to make a light system for my game engine but I've come across a problem which I can't get through.

I have a firecamp and when its dark the light looks cool, when its day it looks normal since there is no light..., but when it starts the transition it reaches a point where the fading gets inverted and it looks so wierd....

I can't find the error on my shader file... please help...

<a href="http://www.youtube.com/v/MBTmyEvSH6E?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/MBTmyEvSH6E?version=3&amp;hl=en_US&amp;start=</a>


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  
#version 330 compatibility

uniform sampler2D texture;
in vec2 texCoords;

uniform float dayLight;

uniform vec2 lightPosition[50];
uniform vec3 lightColor[50];
uniform float lightIntensity[50];
uniform float lightInUse[50];
uniform float lightType[50];
uniform float lightSize[50];
uniform float lightFacing[50];

void main() {      
   float day = dayLight * 2;
   vec4 color = vec4(1.0, 1.0, 1.0, 1.0);
   vec4 ocolor = vec4(1.0, 1.0, 1.0, 1.0);
   vec4 tex = texture2D(texture, gl_TexCoord[0].st);
   color = tex;
     
   float alpha = 1.0;
   if (tex.x == 1.0 && tex.y == 0.0 && tex.z == 1.0) {
      alpha = 0.0;
   }
   
   vec4 result = vec4(color.xyz, alpha);
   color = result;
   ocolor = result;
   
   int num = 0;
   int changed = 0;        
   
   for (int i = 0; i < 50; i++) {
      if (lightInUse[i] == 1) {  
         vec2 pos = lightPosition[i];
         float distance = length(pos - gl_FragCoord.xy);
         if (pos.x == 0 && pos.y == 0) continue;
         vec3 col = lightColor[i];
         float ints = lightIntensity[i];
         
         float attenuation = 1.0 / distance;
         
         float falloff = 80;
         falloff -= distance / 25.0f / ints;        
             
         if (attenuation >= 0.010) {
            color *= vec4(attenuation, attenuation, attenuation, pow(attenuation, 3)) * vec4((col / distance * 15) * ints, 1.0) + 0.01;            
            color /= (distance / (ints * falloff));              
            changed = 1;
            num++;
         }
           
      }
   }
   if (changed == 1) color *= 30.0 * pow(166.0, float(num - 1)) + 1;
   else color = vec4(color * vec4(day, day, day, day));
   
   vec4 dcolor = vec4(ocolor * vec4(day, day, day, day));  
   
   if (min(dcolor, color) == color) color = dcolor;
   
   if (min(result, color) == color) gl_FragColor = color;
   else gl_FragColor = result;
}



Thank you,
João Lourenco.

PS: If there is a better way of doing this, please tell me, I'm trying to learn more about this.
21  Games Center / Featured Games / Re: State of Fortune on: 2014-09-05 13:49:16
Thresher's have this bug too as well as Flour mill's, also if I put the itens on the upper part of the machine there is no animation and on the lower part it has.

PS: Also Ive just tested and the machines can run twice the load they should with this bug...
22  Games Center / Featured Games / Re: State of Fortune on: 2014-09-05 13:14:06
Mike, I've found a nother bug...

Wow.... As I write this I'm trying to replicate the bug... and its seens soooooooo wierd...

The bug is: the same lady (saller) has multiple inventories...

I just found two inventories.... if u aim to the feet and open her invetory u get one, if u aim to the head u have another one... its this normal?

23  Game Development / Newbie & Debugging Questions / Fixing a spotlight shader in glsl on: 2014-07-30 13:02:38
Hello,

I'm having some troubles with my math that I would like a quick help on.
My goal is to have a spotlight that only has light from a customizable angle to another customizable angle, for example from 0 to 90 degrees.
Though my shader seens to be duplicating this angles, like if it is performing on both positive and negative side...

here is my shader code:
Quote
uniform float lightInt;
uniform vec2 lightLocation;
uniform vec3 lightColor;
uniform float lightType;

void main() {
   float distance = length(lightLocation - gl_FragCoord.xy);
   float attenuation = lightInt / distance;
   vec4 color = vec4(attenuation, attenuation, attenuation, pow(attenuation, 3) * 10) * vec4(lightColor * lightInt, 1);
   
   color = vec4(0, 0, 0, 0);
   float h = distance;
   float x = lightLocation.x - gl_FragCoord.x;
   
   float angle = degrees(acos(x / h));
   if (angle >= 0 && angle <= 90) {
      color = vec4(attenuation, attenuation, attenuation, pow(attenuation, 3) * 10) * vec4(lightColor * lightInt, 1);
   }
   gl_FragColor = color;
}

this is how it looks,



I guess there is something wrong on the math... don't know what though...

Thank you for your time, Joaogl.
24  Game Development / Newbie & Debugging Questions / Re: OpenGL Fragments on: 2014-07-28 19:19:28
Thank's guys, I have a question on the fragments, how can I compare two vec4?

I want to only change the result if the calculated color(its in a vec4) is darker then the existent color(its a vec4 too)
25  Game Development / Newbie & Debugging Questions / Re: OpenGL Fragments on: 2014-07-27 21:47:25
thank you for your anwser I had actually never thought of that... I'll try it
26  Game Development / Newbie & Debugging Questions / OpenGL Fragments on: 2014-07-24 14:34:26
Hello guys, I'm here searching for a quick help cause I'm not being successful...

I'm trying to make a Fragment that will apply lighting effect on 2D walls, the thing is, I made two separate algorithms for it, one applies the light effect, and one applies the day light effect.

the problem is the light effect its making everything totally black exept the lighting area...

Fragment for light effect
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  
#version 330 compatibility

uniform sampler2D texture;
in vec2 texCoords;

uniform float dayLight;

uniform vec2 lightPosition[50];
uniform vec3 lightColor[50];
uniform float lightIntensity[50];
uniform float lightInUse[50];

void main() {  
   vec4 color = vec4(1.0, 1.0, 1.0, 1.0);
   vec4 tex = texture2D(texture, gl_TexCoord[0].st);
   color = tex;
   
   int num = 0;  
   for (int i = 0; i < 50; i++) {
      if (lightInUse[i] == 1) {
         vec2 pos = lightPosition[i];
         float distance = length(pos - gl_FragCoord.xy);
         if (pos.x == 0 && pos.y == 0) continue;
         num++;
         vec3 col = lightColor[i];
         float ints = lightIntensity[i];
         
         float distance = length(pos - gl_FragCoord.xy);
         float attenuation = 1.0 / distance;
         
         float falloff = 80;
         falloff -= distance / 25.0f / ints ;      
         
         color *= vec4(attenuation, attenuation, attenuation, pow(attenuation, 3)) * vec4((col / distance * 15) * ints, 1.0) + 0.01;
         
         color /= (distance / (ints * falloff));
      }
   }
   color *= 30.0 * pow(166.0, float(num - 1)) + 1;
     
   gl_FragColor = color;
}


Fragment for day light effect
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
#version 330 compatibility

uniform sampler2D texture;
in vec2 texCoords;

uniform float dayLight;

void main() {  
   vec4 color = vec4(1.0, 1.0, 1.0, 1.0);
   vec4 tex = texture2D(texture, gl_TexCoord[0].st);
   color = tex;
   
   color = vec4(color * vec4(dayLight, dayLight, dayLight, dayLight));  
   color *= 30.0 * pow(166.0, float(num - 1)) + 1;
     
   gl_FragColor = color;
}


How can I combine these two together?

 Thank you for your time.
27  Discussions / General Discussions / Mac error? on: 2014-02-11 14:01:28
Hello, I dont know where to place this topic so please if its wrong someone move it to the righ place...

I tried to run my Game Launcher on mac and for some reason it crashed... The crash error:

1  
2  
3  
4  
5  
10/02/14 11:21:09,412 ReportCrash[1474]: Saved crash report for CalendarAgent[1475] version 7.0 (174) to /Users/Paulo/Library/Logs/DiagnosticReports/CalendarAgent_2014-02-10-112109_MacBook-Pro-de-Paulo.crash
10/02/14 11:21:09,414 ReportCrash[1474]: Removing excessive log: file:///Users/Paulo/Library/Logs/DiagnosticReports/CalendarAgent_2014-02-10-111736_MacBook-Pro-de-Paulo.crash
10/02/14 11:21:09,415 ReportCrash[1474]: Failed to write crash history to file:///Users/Paulo/Library/Containers/com.apple.CalendarAgent/Data/Library/Application%20Support/CrashReporter/CalendarAgent_59AEB35F-8F4F-5A9D-B26E-AAA0F463F75A.plist.
10/02/14 11:21:19,891 com.apple.launchd.peruser.501[162]: (com.apple.CalendarAgent[1478]) Job appears to have crashed: Segmentation fault: 11
10/02/14 11:21:19,891 com.apple.launchd.peruser.501[162]: (com.apple.CalendarAgent) Throttling respawn: Will start in 10 seconds


And like this one I have +2000 lines that are the same... After this I turned off the mac and when I tried to turn it back on I had to restore from a backup because the OS X didn't want to start... does someone know why this is happening?
28  Games Center / Featured Games / Re: State of Fortune on: 2014-02-06 19:58:08
Also... I've done something that I havent for a long time.... I FOUND A BUG! Cheesy

On Login:


On Teleport:
29  Games Center / Featured Games / Re: State of Fortune on: 2014-02-06 19:51:15
I'm still waiting for some new stuff Cheesy
And people online too Cheesy
30  Games Center / Featured Games / Re: State of Fortune on: 2013-12-24 19:26:10
There is one thing left on the update... a texture change on the trees to make them christmas trees during  day 25 ...
Pages: [1] 2 3
 
deepthought (49 views)
2015-06-30 15:39:44

deepthought (56 views)
2015-06-30 15:39:09

deepthought (65 views)
2015-06-30 15:36:52

Za\'Anzabar (43 views)
2015-06-29 05:44:54

TritonDreyja (49 views)
2015-06-24 17:10:40

CopyableCougar4 (52 views)
2015-06-23 00:34:45

BurntPizza (58 views)
2015-06-21 20:36:46

cookiecompiler (98 views)
2015-06-11 15:42:53

cookiecompiler (58 views)
2015-06-11 15:41:14

NegativeZero (82 views)
2015-06-11 09:49:18
How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14
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!