Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (553)
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: Bitmap Font on: 2014-06-09 18:32:47
Watch this video: https://www.youtube.com/watch?v=62YVcYT4mSE
2  Java Game APIs & Engines / OpenGL Development / Re: Problems with Modern OpenGL lighting on: 2014-05-15 13:44:30
@danny02

Thanks for that. So every time a make another pass at the render the last light in the array always seems to override the other lights, so it only renders the last one
3  Java Game APIs & Engines / OpenGL Development / Re: Problems with Modern OpenGL lighting on: 2014-05-14 18:51:25
Another question: how would I modify this shader to add multiple lights? I've got a ArrayList with some lights and tried using a for-loop to cycle through the lights when I set a uniform, that just gives me lights blinking on and off after each other.
4  Java Game APIs & Engines / OpenGL Development / Re: Problems with Modern OpenGL lighting on: 2014-05-14 17:00:33
Cheers for that @Riven. Tried it, it works great!
5  Java Game APIs & Engines / OpenGL Development / Re: Problems with Modern OpenGL lighting on: 2014-05-14 07:52:01
Thanks everyone! It works now! http://i.imgur.com/hoTKoxP.png
If anyone is having the same issue just message me and I'll give you the code.
6  Java Game APIs & Engines / OpenGL Development / Re: Problems with Modern OpenGL lighting on: 2014-05-13 22:17:33
Okay, the lighting kinda works but I can adjust it later. But whenever the camera rotates or moves the light seems to move. Any reason why?

Here is the updated shaders:

vs
#version 120

varying vec4 color;
varying vec4 vertex;
varying vec4 normal;

uniform mat4 modelMatrix;
uniform mat4 viewMatrix;
uniform mat4 projectionMatrix;
uniform mat4 normalMatrix;

void main() {
    color = gl_Color;
   
   mat4 modelView = viewMatrix * modelMatrix;
    mat4 modelViewProjection = projectionMatrix * viewMatrix * modelMatrix;
   
    vertex = modelView * gl_Vertex;
    normal = normalMatrix * vec4(gl_Normal, 1.0);
    gl_Position = modelViewProjection * gl_Vertex;   
}


fs
#version 120

varying vec4 color;
varying vec4 vertex;
varying vec4 normal;

vec4 lightPos = vec4(5, 0, 5, 1.0);
vec4 ambientTerm = vec4(0.25, 0.25, 0.25, 1.0);
vec4 diffuse = vec4(0.5, 0.5, 0.5, 1.0);
vec4 specular = vec4(0.5, 0.5, 0.5, 1.0);
float shininess = 25;

void main() {
   vec4 N = normalize(normal);
   vec4 light = normalize(lightPos - vertex);
   vec4 eyeCoords = normalize(-vertex);
   vec4 reflection = reflect(light, N);
   
   vec4 diffuseTerm = diffuse * max(dot(N, light), 0.0);
   //diffuseTerm = clamp(diffuseTerm, 0.0, 1.0);
   
   vec4 specularTerm = specular * pow(max(dot(reflection, -eyeCoords), 0.0), shininess);
   specularTerm = clamp(specularTerm, 0.0, 1.0);
   
   gl_FragColor = color * (ambientTerm + diffuseTerm) + specularTerm;
}
7  Java Game APIs & Engines / OpenGL Development / Re: Problems with Modern OpenGL lighting on: 2014-05-12 21:30:21
@Longarmx

Yes, the colour gave a darker image, but the light keeps moving around the world with the camera.
8  Java Game APIs & Engines / OpenGL Development / Re: Problems with Modern OpenGL lighting on: 2014-05-12 19:56:30
@Danny02

Hi, thanks for your reply. I've tried mess around with it and something is still wrong. Here is the code:

Vertex Shader:

#version 120

varying vec4 color;
varying vec3 vertex;
varying vec3 normal;

uniform mat4 modelMatrix;
uniform mat4 viewMatrix;
uniform mat4 projectionMatrix;
uniform mat4 normalMatrix;

void main() {
    color = gl_Color;
    vertex = vec3(viewMatrix * modelMatrix * gl_Vertex);
    normal = vec3(normalize(normalMatrix * gl_Vertex));
    gl_Position = projectionMatrix * viewMatrix * modelMatrix * gl_Vertex;
}

Fragment Shader:
#version 120

varying vec4 color;
varying vec3 vertex;
varying vec3 normal;

vec3 lightSource = vec3(0, 10, 0);
vec4 ambientTerm = vec4(0.1, 0.1, 0.1, 1);
vec4 diffuse = vec4(0.5, 0.5, 0.5, 1);
vec4 specular = vec4(0.1, 0.1, 0.1, 1);
float shininess = 0.1;

void main() {
   vec3 light =  normalize(lightSource - vertex);
   vec3 eyeCoords = normalize(-vertex);
   vec3 reflection = normalize(-reflect(light, normal));
   
   vec4 diffuseTerm = diffuse * max(dot(normal, light), 0.0);
   diffuseTerm = clamp(diffuseTerm, 0.0, 1.0);
   
   vec4 specularTerm = specular * pow(max(dot(reflection, eyeCoords),0.0), 0.3 * shininess);
   specularTerm = clamp(specularTerm, 0.0, 1.0);
   
    gl_FragColor = color + ambientTerm + diffuseTerm+ specularTerm;
}
9  Java Game APIs & Engines / OpenGL Development / Problems with Modern OpenGL lighting on: 2014-05-12 15:28:25
Hello. I am creating a 3D world where I send matrices to a shader to create this. I am now trying to light up my world but it is causing me trouble. This is something I've been struggling for weeks on.

Here's my fragment shader code:
#version 120

varying vec4 color;
varying vec4 normal;
varying vec4 vertex;

uniform mat4 modelMatrix;
uniform mat4 viewMatrix;
uniform mat4 projectionMatrix;
uniform mat4 normalMatrix;

void main() {
   mat4 modelView = viewMatrix * modelMatrix;
   vec3 vertexPos = (modelView * vertex).xyz;
   vec3 surfaceNormal = normalize((normalMatrix*normal).xyz);
   vec3 lightDirection = normalize(gl_LightSource[0].position.xyz - vertexPos);
   float diffuseLightIntensity = max(0, dot(surfaceNormal, lightDirection));
    gl_FragColor.rgb = diffuseLightIntensity * color.rgb;
    gl_FragColor += gl_LightModel.ambient;
    vec3 reflectionDirection = normalize(reflect(-lightDirection, surfaceNormal));
    float specular = max(0.0, dot(surfaceNormal, reflectionDirection));
    
    if (diffuseLightIntensity != 0) {
        float fspecular = pow(specular, gl_FrontMaterial.shininess);
        gl_FragColor += fspecular;
    }
}

Here's my vertex shader code:
#version 120

varying vec4 color;
varying vec4 normal;
varying vec4 vertex;

uniform mat4 modelMatrix;
uniform mat4 viewMatrix;
uniform mat4 projectionMatrix;
uniform mat4 normalMatrix;

void main() {
    color = gl_FrontMaterial.diffuse;
    normal = vec4(gl_Normal, 1.0);
    vertex = gl_Vertex;   
    gl_Position = projectionMatrix * viewMatrix * modelMatrix * gl_Vertex;
}

I have my own maths classes that send the code to the shader and they work fine. Am I missing something with the code? I think I'm drawing the vertices correctly, by using a VBO. Cheers.

Here's what the lighting looks like: http://i.imgur.com/BSEZ9qc.png
10  Game Development / Game Mechanics / Re: Transitioning from Main Menu to entirely different games on: 2013-12-06 18:40:43
I'd use a state based method to transition. Create a super class Screen, for example, and then have you games extends from that. E.g. MarioGameScreen or DungeonCrawlerScreen etc. And in your main loop just type screen.render()  or whatever. To switch screens create a method called setScreen(Screen screen). In this method you will change your current screen (this.screen) to the new screen. You might also want to create another object called lastScreen which when the new screen is set will set the old screen to the lastScreen. Just in case you want to revert.
11  Game Development / Game Mechanics / Difficulties trying to get the pick position from projection and view matrix on: 2013-11-24 19:39:09
Hello there. I am trying to get the pick position in terms of a vector3 from the projection and view matrix. I am using my own math classes. I don't think this is right, could you give any suggestions on how to fix this?

   private Vec3 getPick(Mat4 projection, Mat4 view) {
      Mat4 inverseProject = projection.copy().inverse();
      Mat4 pick = inverseProject.mul(view.copy());
      Vec3 pos = new Vec3(pick.m10, pick.m11, pick.m12);
      return pos;
   }

Cheers.
12  Game Development / Newbie & Debugging Questions / Problems with sending Matrix to openGL on: 2013-11-07 20:34:37
Hello. I have a big problem with my 3D engine. It appears that the current View Matrix is not functioning correctly. I have tried everything with my current knowledge and I don't know the cause. Could you please take a look? The following source code is runnable and just requires LWJGL. Thank you, any help is much appreciated.

http://www.mediafire.com/download/j64xw207bihdq95/Ixion_code.zip
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.

CopyableCougar4 (24 views)
2014-08-22 19:31:30

atombrot (34 views)
2014-08-19 09:29:53

Tekkerue (30 views)
2014-08-16 06:45:27

Tekkerue (28 views)
2014-08-16 06:22:17

Tekkerue (18 views)
2014-08-16 06:20:21

Tekkerue (27 views)
2014-08-16 06:12:11

Rayexar (65 views)
2014-08-11 02:49:23

BurntPizza (41 views)
2014-08-09 21:09:32

BurntPizza (33 views)
2014-08-08 02:01:56

Norakomi (42 views)
2014-08-06 19:49:38
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!