Show Posts
|
|
Pages: [1]
|
|
1
|
Java Game APIs & Engines / OpenGL Development / Re: Lighting + Shadow Mapping GLSL
|
on: 2012-10-04 13:23:31
|
I have found this tutorial. It is written in Delphi, so I have to change the code a little. But apparently I did something wrong. GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER) returns 36054 (GL30.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT) and if I bind the FBO I get the error "Invalid framebuffer operation". original code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| GLuint shadow_map = 0; GLuint shadow_fbo = 0; GLuint shadow_size = 4096; glGenTextures(1, &shadow_map); glBindTexture(GL_TEXTURE_2D, shadow_map); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, shadow_size, shadow_size, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glGenFramebuffersEXT(1, &shadow_fbo); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, shadow_fbo); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, shadow_map, 0); glDrawBuffer(GL_FALSE); glReadBuffer(GL_FALSE); GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); |
my code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| int shadow_map = 0; int shadow_fbo = 0; int shadow_size = 4096;
shadow_map = GL11.glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, shadow_map); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL14.GL_DEPTH_COMPONENT16, shadow_size, shadow_size, 0, GL11.GL_DEPTH_COMPONENT, GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); shadow_fbo = GL30.glGenFramebuffers(); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, shadow_fbo); GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL11.GL_TEXTURE_2D, shadow_map, 0); GL11.glDrawBuffer(GL11.GL_FALSE); GL11.glReadBuffer(GL11.GL_FALSE); int status = GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER); |
I thought that the problem is in line 7. So I tried to pass an empty ByteBuffer, but that did not work.
|
|
|
|
|
2
|
Java Game APIs & Engines / OpenGL Development / Re: Lighting GLSL
|
on: 2012-09-27 10:39:10
|
|
I have solved the problem. Previously I first rotated and translated the modelviewmatrix and then set the light. Now I rotate the modelviewmatrix first, then set the light and move the modelviewmatrix at the end.
But now I would like to use shadow mapping, but I can't find a tutorial, that I understand. I understand the theory (Render the scene from the view of the light, read the z-Buffer and test in the fragment shader, if z is bigger than the z from the rendering from light position), but not how to do this.
|
|
|
|
|
3
|
Java Game APIs & Engines / OpenGL Development / Lighting + Shadow Mapping GLSL
|
on: 2012-09-25 20:14:03
|
Hi, I want to use diffuse and ambient light. My problem is, that if I move with the camera (translate the ModelViewMatrix) the brightness of the faces changes although the light should be fixed. Here is my vertex shader: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| attribute vec3 position; attribute vec3 normal;
void main() { gl_Position = gl_ModelViewProjectionMatrix * vec4(position, 1); gl_Normal = normalize(gl_NormalMatrix * normal); vec3 light = normalize(vec3(gl_LightSource[0].position));
float NdotL = max(dot(gl_Normal, light), 0.0); vec4 ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient; vec4 globalAmbient = gl_LightModel.ambient * gl_FrontMaterial.ambient; gl_FrontColor = NdotL * gl_LightSource[0].diffuse + globalAmbient + ambient; } |
I set the light position each frame after translate the MoselViewMatrix: 1
| GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, mPosition); |
What should I do? PS: Is there an IDE/addon for Eclipse for GLSL?
|
|
|
|
|
4
|
Java Game APIs & Engines / OpenGL Development / Re: glDrawArrays - problem with normals
|
on: 2012-09-21 12:09:48
|
Ok, I have read some article about shader. Now I want to make a vertex shader that simple set the attribute 0 as position of the vertex and the attribute 1 as normal. And a fragment shader that do the same that it does normal (because I have read that I can not use only a vertex shader without fragment shader). I have found that code in a tutorial. But there are some things I don't understand. 1. Does that mean, that I must set the matrices projModelViewMatrix and normalMatrix each time before I render? 2. How does OpenGL know, that VertexOut.normal is the normal for that vertex? / How I can change the normal in the vertex shader if gl_Normal is readable only? 3. How I can make a "default" fragment shader? 4. Does it makes a difference in performance if I use old GLSL Methodes like ftransform()? 5. Will it be later more complicated to use shadow mapping, if I use me own shader? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| #version 150
layout (std140) uniform Matrices { mat4 projModelViewMatrix; mat3 normalMatrix; };
in vec3 position; in vec3 normal;
out VertexData { vec3 normal; } VertexOut;
void main() { VertexOut.normal = normalize(normalMatrix * normal); gl_Position = projModelViewMatrix * vec4(position, 1.0); } |
|
|
|
|
|
5
|
Java Game APIs & Engines / OpenGL Development / Re: glDrawArrays - problem with normals
|
on: 2012-09-20 16:56:29
|
|
I've found out that glVertexPointer(...) assumes no GL_BYTE as data type.
Maybe it would be better if I do it in a different way, because otherwise I will have to send twice as many bytes for the coordinates to the graphics card.
It is important for me that the frame rate is not going down even if I render many cubes and some of them change each frame.
|
|
|
|
|
6
|
Java Game APIs & Engines / OpenGL Development / Re: glDrawArrays - problem with normals
|
on: 2012-09-20 10:44:26
|
I used this command because I was trying to work with this tutorial to make my code ready for future versions of OpenGL ( http://lwjgl.org/wiki/index.php?title=The_Quad_with_DrawArrays). Do you mean so? With this code I get the error: Invalid enum Here I'd use no VAO. Is this right? And is this a good way to render my cubes? Or are there better? 1 2 3 4 5 6 7 8 9 10 11 12
| ByteBuffer verticesBuffer = BufferUtils.createByteBuffer(numberOfVerices * 6); verticesBuffer.put(verticesAndNormals, 0, numberOfVerices * 6); verticesBuffer.flip(); vboId = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesBuffer, GL15.GL_DYNAMIC_DRAW); GL11.glVertexPointer(3, GL11.GL_BYTE, 6, 0); GL11.glNormalPointer(GL11.GL_BYTE, 6, 3);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); |
1 2 3 4 5 6 7 8 9 10 11
| GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY); GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
GL11.glDrawArrays(GL11.GL_QUADS, 0, vertexCount);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
GL11.glDisableClientState(GL11.GL_NORMAL_ARRAY); GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY); |
|
|
|
|
|
9
|
Java Game APIs & Engines / OpenGL Development / Re: glDrawArrays - problem with normals
|
on: 2012-09-19 19:04:23
|
Make sure your offsets are right as it looks like you are interleaving your VBO.
1 float is 4 bytes.
So a 3 float vertex is 4*3 bytes
I am still learning this stuff too.
Yes I interleaving the VBO and I am sure that it is not because of that. (3 bytes for coordinate, 3 bytes for normals) Could it be that I have to use shaders to tell OpenGL that the second attribute are the normals?
|
|
|
|
|
10
|
Java Game APIs & Engines / OpenGL Development / glDrawArrays - problem with normals
|
on: 2012-09-19 18:13:22
|
Hi, i try to make a Voxel Engine. I have a VAO that have a VBO. In this are the vertex and the normals of the Cubes. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| vaoId = GL30.glGenVertexArrays(); GL30.glBindVertexArray(vaoId);
ByteBuffer verticesBuffer = BufferUtils.createByteBuffer(numberOfVerices * 6); verticesBuffer.put(verticesAndNormals, 0, numberOfVerices); verticesBuffer.flip();
vboId = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesBuffer, GL15.GL_DYNAMIC_DRAW); GL20.glVertexAttribPointer(0, 3, GL11.GL_BYTE, false, 6, 0); GL20.glVertexAttribPointer(1, 3, GL11.GL_BYTE, false, 6, 3); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL30.glBindVertexArray(0); |
I can render the cubes like this: 1 2 3 4 5 6 7
| GL30.glBindVertexArray(vaoId); GL20.glEnableVertexAttribArray(0);
GL11.glDrawArrays(GL11.GL_QUADS, 0, vertexCount);
GL20.glDisableVertexAttribArray(0); GL30.glBindVertexArray(0); |
But how can I say OpenGL that, the second VBO includes the normals? And is this the right way to render my Cubes? Or is there a better?
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|