Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [SOLVED][lwjgl] Issues with FBO for Post Processing  (Read 752 times)
0 Members and 1 Guest are viewing this topic.
Offline bogieman987
« Posted 2014-05-03 22:27:21 »

Hi,

I'm trying to implement a framebuffer in order to do post processing.

However, I'm a bit stuck.
I get no errors when creating the framebuffer, or even during runtime.
Shaders produce no errors in compiling and linking.
Although it does produce an error val of 1280, but the message equaling null. Which is puzzling.
The error was from when I was checking the framebuffer completeness, I was putting the wrong value in the target for
1  
GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER);

Of which it does indeed complete.

This is what the code snippet looks like.
1  
2  
3  
int val = GL11.glGetError();
      System.out.println("Error Val: " + Integer.toString(val));
      System.out.println("Error Message: " + GLU.gluGetString(val));

This returns GL_NO_ERROR but not GL_FRAMEBUFFER_COMPLETE
Besides that no errors.

Yet, it doesn't render anything, other than the refresh color.

Oh the growth pains of learning....

Here's some images:
Just the default framebuffer.


With my unsuccessful attempt at implementing a framebuffer.
(Changed the refresh color, so it's easier to tell if there's any change)


Here's the code where the rendering is done.
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  
107  
108  
109  
110  
111  
112  
public void update(GameObject[] gameObject) {
      updateMatrices();
     
      // Temp
     if(fb) {
         GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, getFrameBuffer().getFBO());
      } else GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
           
      // Temp
     float[] color1 = {0.4f, 0.6f, 0.9f, 0f};
      setClCol(color1);
      setClColBuffer(BufferUtils.createFloatBuffer(getClCol().length));
      getClColBuffer().put(getClCol());
      getClColBuffer().flip();
           
      GL11.glViewport(0, 0, getCamera().getWidthi(), getCamera().getHeighti());
      GL30.glClearBuffer(GL11.GL_COLOR, 0, getClColBuffer());
      GL30.glClearBuffer(GL11.GL_DEPTH, 0, getClDepthBuffer());
     
      GL20.glUseProgram(getShader().getShaderProgram());
         
      // Projection Matrix
     getProjectionMatrix().store(getMatrixBuffer());
      getMatrixBuffer().flip();
      GL20.glUniformMatrix4(getShader().getUniform(Uniform.PROJECTION).getLocation(), false, getMatrixBuffer());
     
      // View Matrix
     getViewMatrix().store(getMatrixBuffer());
      getMatrixBuffer().flip();      
      GL20.glUniformMatrix4(getShader().getUniform(Uniform.VIEW).getLocation(), false, getMatrixBuffer());
     
      // These two things will be removed.
     GL11.glLineWidth(5f);
      GL11.glPointSize(10f);
     
      for(int i = 0; i < gameObject.length; i++) {
         // Model matrix
        for(int j = 0; j < gameObject[i].getNumOf(); j++) {
            gameObject[i].getModelMatrix()[j].store(getMatrixBuffer());
         }
         getMatrixBuffer().flip();
         GL20.glUniformMatrix4(getShader().getUniform(Uniform.MODEL).getLocation(), false, getMatrixBuffer());
         
         GL13.glActiveTexture(GL13.GL_TEXTURE0);
         GL11.glBindTexture(GL11.GL_TEXTURE_2D, gameObject[i].getMaterial().getVboT());
         
         GL30.glBindVertexArray(gameObject[i].getModel().getVao());
         GL20.glEnableVertexAttribArray(0);
         GL20.glEnableVertexAttribArray(1);
         GL20.glEnableVertexAttribArray(2);
         
         GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, gameObject[i].getModel().getVboI());
         
         // If statement is temporary, will be removed
        // It will and will render tris not lines.
        if(lines)GL31.glDrawElementsInstanced(GL11.GL_LINES, gameObject[i].getModel().getNumOfIndeces(),
                                 GL11.GL_UNSIGNED_INT, 0, gameObject[i].getNumOf());
         else GL31.glDrawElementsInstanced(GL11.GL_TRIANGLES, gameObject[i].getModel().getNumOfIndeces(),
               GL11.GL_UNSIGNED_INT, 0, gameObject[i].getNumOf());
      }
         
      // If statement is temporary, will be removed
     if(fb) {
         // Render frame buffer  
        GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
         
         // Temp
        float[] color2 = {0.2f, 0.3f, 0.5f, 0f};
         setClCol(color2);
         setClColBuffer(BufferUtils.createFloatBuffer(getClCol().length));
         getClColBuffer().put(getClCol());
         getClColBuffer().flip();
         
         GL11.glViewport(0, 0, getCamera().getWidthi(), getCamera().getHeighti());
         GL30.glClearBuffer(GL11.GL_COLOR, 0, getClColBuffer());
         GL30.glClearBuffer(GL11.GL_DEPTH, 0, getClDepthBuffer());
         
         GL11.glBindTexture(GL11.GL_TEXTURE_2D, getFrameBuffer().getTexture());
         GL11.glBindTexture(GL11.GL_TEXTURE_2D, getFrameBuffer().getDepth());
         
         GL20.glUseProgram(getPost().getShaderProgram());
         
         // Draw square
        GL30.glBindVertexArray(getBufferQuad().getVao());
         GL20.glEnableVertexAttribArray(0);
         GL20.glEnableVertexAttribArray(1);
         
         GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, getBufferQuad().getVboI());
         
         // If statement is temporary, will be removed
        if(lines) GL11.glDrawElements(GL11.GL_LINES, getBufferQuad().getNumOfIndeces(), GL11.GL_UNSIGNED_BYTE, 0);
         else GL11.glDrawElements(GL11.GL_TRIANGLES, getBufferQuad().getNumOfIndeces(), GL11.GL_UNSIGNED_BYTE, 0);
      }
     
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
      GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
      GL20.glDisableVertexAttribArray(0);
      GL20.glDisableVertexAttribArray(1);
      GL20.glDisableVertexAttribArray(2);
      GL30.glBindVertexArray(0);
     
      GL20.glUseProgram(0);
           
      getCamera().reset();

      if(getIfSync()) {
         Display.sync(getFps());
      }
      Display.update();
     
      ErrorCheck.checkForGLError(" * Render.java * ");
   }


Where I create the framebuffer.
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  
private void init(int width, int height, int[] buffers) {
      // This is here just in case it fails some where,
     // and to make it look pretty than a simple log in the console.
     System.out.println("Initiating Framebuffer" + "\n -----------------------------");
     
      setFBO(GL30.glGenFramebuffers());
      GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, getFBO());
     
      // Texture for color
     setTexture(GL11.glGenTextures());
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, getTexture());
      GL42.glTexStorage2D(GL11.GL_TEXTURE_2D, 1, GL30.GL_RGBA16F, width, height);
     
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
     
      // Texture for depth
     setDepth(GL11.glGenTextures());
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, getDepth());
      GL42.glTexStorage2D(GL11.GL_TEXTURE_2D, 1 , GL30.GL_DEPTH_COMPONENT32F, width, height);
     
      GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, getTexture(), 0);
      GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, getDepth(), 0);
     
      IntBuffer drawBuffers = BufferUtils.createIntBuffer(buffers.length);
      for(int i = 0; i < buffers.length; i++) {
         drawBuffers.put(buffers[i]);
      }
      drawBuffers.flip();
      GL20.glDrawBuffers(GL30.GL_COLOR_ATTACHMENT0);
     
      errorCheck();
      System.out.println("Framebuffer Initiated" + "\n -----------------------------");
   }


Here are my shaders.
Main vertex.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
#version 430 core

layout(location = 0) in vec4 in_Position;
layout(location = 1) in vec2 in_TextureCoord;

out VS_OUT {
   vec2 pass_TextureCoord;
   vec4 pass_Color;
} vs_out;

uniform mat4 proj_matrix;
uniform mat4 view_matrix;
uniform mat4 model_matrix;

void main(void) {      
   gl_Position = in_Position;              
   gl_Position = proj_matrix * view_matrix * model_matrix * in_Position;

   vs_out.pass_Color = vec4(1.0, 1.0, 1.0, 1.0);
   vs_out.pass_TextureCoord = in_TextureCoord;
}


Main Fragment.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
#version 430 core

uniform sampler2D diffuse_Tex;

in VS_OUT {
   vec2 pass_TextureCoord;
   vec4 pass_Color;
} fs_in;

out vec4 out_Color;

void main(void) {
   out_Color = texture(diffuse_Tex, fs_in.pass_TextureCoord);
}


Post Vertex.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
#version 430 core

layout(location = 0) in vec4 in_Position;
layout(location = 1) in vec2 in_TexCoord;

out vec2 pass_TexCoord;

void main(void) {      
   gl_Position = in_Position;              
   
   pass_TexCoord = in_TexCoord;
}


Post Fragment
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
#version 430 core

uniform sampler2D fbo_texture;
uniform sampler2D fbo_depth;

in vec2 pass_TextureCoord;

out vec4 out_Color;

void main(void) {  
   out_Color = texture2D(fbo_texture, pass_TextureCoord);
}


Um, if there's any other code needed, please let me know, I prefer to try and figure these things out myself,
but this has me stumped.  Huh

Oh and sorry for what I have done to poor suzanne.

Any help is appreciated.

Offline bogieman987
« Reply #1 - Posted 2014-05-06 18:55:01 »

Sorry for the double post but it's been a few days, and I still haven't figured this out.
No-one else seems to know either  Undecided

I wondering if the "line rendering weirdness" is what's causing my framebuffer to not show.

Is there anyone out there with some inkling of what's the cause, and/or a fix?

Edit: Turns out, I misunderstood GL_LINES. So that sorts the "line rendering weirdness" out.

Offline bogieman987
« Reply #2 - Posted 2014-05-11 21:19:46 »

Ok, so the issue has been solved.

It turns out that the issue simply lied with the square used to render the framebuffer texture to.

Pages: [1]
  ignore  |  Print  
 
 

 

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

The first screenshot will be displayed as a thumbnail.

pw (37 views)
2014-07-24 01:59:36

Riven (38 views)
2014-07-23 21:16:32

Riven (26 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21

Zero Volt (50 views)
2014-07-17 23:47:54

danieldean (42 views)
2014-07-17 23:41:23

MustardPeter (44 views)
2014-07-16 23:30:00

Cero (60 views)
2014-07-16 00:42:17

Riven (57 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!