Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (601)
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 878 times)
0 Members and 1 Guest are viewing this topic.
Offline bogieman987
« Posted 2014-05-03 20: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 16: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 19: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  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (42 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (51 views)
2014-12-03 16:27:13

CopyableCougar4 (48 views)
2014-11-29 21:32:03

toopeicgaming1999 (115 views)
2014-11-26 15:22:04

toopeicgaming1999 (103 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!