Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (524)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (592)
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  
  problem with Frame Buffer Objects  (Read 2622 times)
0 Members and 1 Guest are viewing this topic.
Offline roland
« Posted 2011-11-27 11:36:20 »

Hi, I have a problem with frame buffer objects. I want to render to a texture once, then not have to render to it again. I want to draw this texture repeatedly each frame. It never changes. But with FBO, I have to render it each frame, otherwise the image goes black!  Angry
is there a way to fix this?
Thanks,
roland

Edit: sorry this is supposed to be in the LWJGL section
Offline theagentd

« JGO Bitwise Duke »


Medals: 361
Projects: 2
Exp: 8 years



« Reply #1 - Posted 2011-11-27 11:41:30 »

It doesn't automatically clear your textures. You're doing something wrong.

Myomyomyo.
Offline roland
« Reply #2 - Posted 2011-11-27 12:08:40 »

Thanks for the reply theagentd.

I bind the texture once, draw on it, then unbind it. I can't see why it would get affected after that.

Could you have a look at my offscreen image class?
http://pastebin.com/QqeRXc9D

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
//init
m_offscreenTexture = new OffscreenTexture(64,64);

//in draw
if (!m_offscreenTexture.Drawn())
{
                //will only be called once
          m_offscreenTexture.Bind();
          m_offscreenTexture.TestDraw();
          m_offscreenTexture.UnBind();
}

GL11.glBindTexture(GL11.GL_TEXTURE_2D, m_offscreenTexture.GetTextureID());  
Graphics.DrawTexturedSquare(0, 0, 40, 40);
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline roland
« Reply #3 - Posted 2011-11-27 12:36:48 »

I fixed it. Just got rid of the slick util Texture and uncommented the lines

1  
2  
3  
4  
5  
6  
m_iTextureID = GL11.glGenTextures();
          // initialize color texture
          GL11.glBindTexture(GL11.GL_TEXTURE_2D, m_iTextureID);                           // Bind the colorbuffer texture
          GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);            // make it linear filterd
          GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, m_iWidth, m_iHeight, 0,GL11.GL_RGBA, GL11.GL_INT, (java.nio.ByteBuffer) null);   // Create the texture data
     


Thanks  Grin
Offline hvince95

Junior Devvie


Medals: 1
Projects: 2



« Reply #4 - Posted 2012-09-30 08:55:25 »

Sorry to bring this back from the dead, but I've been trying to get a frame buffer object up and running in my world, but cannot manage it!

I have taken rolands OffscreenTexture class and kept it exactly the same except for the testDraw method.  I changed that to this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
public void TestDraw() {
      GL11.glLoadIdentity();
      GL11.glColor4b((byte)255, (byte)100, (byte)100, (byte)255);
     
      GL11.glBegin(GL11.GL_QUADS);
         GL11.glVertex3f(0, 0, 0);
         GL11.glVertex3f(200, 0, 0);
         GL11.glVertex3f(200, 200, 0);
         GL11.glVertex3f(0, 200, 0);
      GL11.glEnd();
   }


Now, in the main game, an OffscreenTexture is created:
1  
OffscreenTexture buffer = new OffscreenTexture(900, 500);

and this code is called once:
1  
2  
3  
buffer.Bind();
buffer.TestDraw();
buffer.UnBind();


and later, every frame this code is executed:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
private void renderGame() {
     
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
     
      GL11.glEnable(GL11.GL_TEXTURE_2D);
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, buffer.getTextureID());
     
      GL11.glBegin(GL11.GL_QUADS);
      GL11.glTexCoord2f(0, 0);
      GL11.glVertex2i(0, 0);
   
      GL11.glTexCoord2f(1, 0);
      GL11.glVertex2i(900, 0);
   
      GL11.glTexCoord2f(1, 1);;
      GL11.glVertex2i(900, 500);
   
      GL11.glTexCoord2f(0, 1);
      GL11.glVertex2i(0, 500);
      GL11.glEnd();
   }


Is there a problem with the way I have used the opengl to draw everything rather than graphics, or is the problem somewhere else?
Offline theagentd

« JGO Bitwise Duke »


Medals: 361
Projects: 2
Exp: 8 years



« Reply #5 - Posted 2012-09-30 15:20:35 »

Assuming the OffscreenTexture class does all the necessary setup (glViewport() comes to mind  Roll Eyes), your problem is most likely just that you're setting the texture settings before binding the texture. Just move your glTexParameteri()s to after you've bound the texture. Most likely it's not working because the texture is set to using mipmaps ---> the texture is considered incomplete since you don't have mipmaps.

Myomyomyo.
Offline hvince95

Junior Devvie


Medals: 1
Projects: 2



« Reply #6 - Posted 2012-10-01 00:01:53 »

That doesn't seem to have helped.

I'm wondering if I need to add some code in the renderGame() method, after glEnd(), to tell OpenGL to render the buffer to the Display.  Or does it do this automatically?
Offline theagentd

« JGO Bitwise Duke »


Medals: 361
Projects: 2
Exp: 8 years



« Reply #7 - Posted 2012-10-01 00:12:26 »

Maybe OffscreenTexture already does this, but try to add a glViewport() call each time you switch render target (= bind or unbind an FBO) to the correct size. Can you also post the code for OffscreenTexture?

Myomyomyo.
Offline hvince95

Junior Devvie


Medals: 1
Projects: 2



« Reply #8 - Posted 2012-10-01 00:55:06 »

I've actually got the viewport the same throughout the whole program.
Here is the OffScreenTexture class (I renamed a few things just to confuse you Smiley)
http://pastebin.java-gaming.org/befe25d6728

As usual, this is called once:
1  
2  
3  
4  
   FrameBuffer buffer = new FrameBuffer(900, 500);
      buffer.bind();
      buffer.render();
      buffer.unBind();

and then this is called every frame:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
private void renderGame() {
     
      GL11.glEnable(GL11.GL_TEXTURE_2D);
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, buffer.getTextureID());
     
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
     
      GL11.glBegin(GL11.GL_QUADS);
         GL11.glTexCoord2f(0, 0);
         GL11.glVertex2i(0, 0);
     
         GL11.glTexCoord2f(1, 0);
         GL11.glVertex2i(900, 0);
     
         GL11.glTexCoord2f(1, 1);;
         GL11.glVertex2i(900, 500);
         
         
         GL11.glTexCoord2f(0, 1);
         GL11.glVertex2i(0, 500);
      GL11.glEnd();
}


Thankyou for your help.
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.

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

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

toopeicgaming1999 (10 views)
2014-11-26 15:20:08

SHC (24 views)
2014-11-25 12:00:59

SHC (24 views)
2014-11-25 11:53:45

Norakomi (27 views)
2014-11-25 11:26:43

Gibbo3771 (24 views)
2014-11-24 19:59:16

trollwarrior1 (37 views)
2014-11-22 12:13:56

xFryIx (75 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!