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 (552)
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  
  Framebuffer viewport problem  (Read 1922 times)
0 Members and 1 Guest are viewing this topic.
Offline RobinB

JGO Ninja


Medals: 44
Projects: 1
Exp: 3 years


Spacegame in progress


« Posted 2013-07-31 17:29:36 »

Im having issues with the current framebuffer, what should be really easy to solve, but im breaking my head over it.
Currently my implementation of binding / unbinding looks like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
    public void Bind(){
        EXTFramebufferObject.glBindFramebufferEXT( EXTFramebufferObject.GL_FRAMEBUFFER_EXT, FBOId);
       
        glPushAttrib(GL_VIEWPORT_BIT);
        glPushAttrib(GL_COLOR_BUFFER_BIT);
        glViewport( 0, 0, viewportwidth, viewportheight);
        glMatrixMode(GL_PROJECTION);  
        glClearColor(0,0,0,0);
       
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    }
   
    public void Unbind(){        
        EXTFramebufferObject.glBindFramebufferEXT( EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0);
        glPopAttrib();
        glPopAttrib();
    }


However the framebuffer does not scale to viewportwidth, viewportheight
Instead, the output is an oddly scaled version between the framebuffer dimensions and the normal screen dimensions.

Im trying to render an image to a buffer (512, 512), the screen is however (1200, 900)

so how do i set the framebuffer to 512, 512 instead of having it locked at 1200, 900?
Any help appriciated.
Offline RobinB

JGO Ninja


Medals: 44
Projects: 1
Exp: 3 years


Spacegame in progress


« Reply #1 - Posted 2013-07-31 19:39:10 »

I know it has something to to with glOrtho, but when i change this, everything gets really messed up.
Offline Redocdam

Senior Member


Medals: 17



« Reply #2 - Posted 2013-07-31 20:10:12 »

It's possible things aren't getting attached correctly.
I'm not too familiar with the way you're binding the FBO (fixed pipeline ?).

Aside from that, my process is similar to what's being done here:
http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-14-render-to-texture/

Basically you generate an FBO handle, set some parameters and attach some textures to it.
I don't see where any textures are being attached, so maybe you're doing it in a different place?

At the very least, this should help. Check if the FBO is getting created properly.
1  
2  
3  
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE){
      System.out.println("Why Do you HATE ME!?!");
}

There's a couple error codes it will spit out if things didn't go according to plan. Unfortunately I'm stuck in my 9-5 prison, so I'll dig those out of my project once my captors feel I've kludged enough code for today.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline quew8

JGO Coder


Medals: 29



« Reply #3 - Posted 2013-07-31 21:18:32 »

Firstly, off topic. In OpenGL, any constant ending with _BIT are bitfields. This means that they can be bitwise or d together just like you do with COLOR_BUFFER_BIT and DEPTH_BUFFER_BIT.

So
1  
2  
3  
4  
5  
glPushAttrib(GL_VIEWPORT_BIT);
glPushAttrib(GL_COLOR_BUFFER_BIT);
...
glPopAttrib();
glPopAttrib();


can become
1  
2  
3  
glPushAttrib(GL_VIEWPORT_BIT | GL_COLOR_BUFFER_BIT);
...
glPopAttrib();

just a little pointer.

Now, on topic. You set the matrix mode to GL_PROJECTION but you don't actually load the identity matrix or anything so whatever matrix was there before is still there. Just try adding glLoadIdentity() after setting the matrix mode.

Secondly, I wonder if you know what pushing GL_COLOR_BUFFER_BIT does? This page will clarify if you don't http://www.opengl.org/sdk/docs/man2/ (it just seemed an odd thing to be doing there)

Lastly, make sure that viewportwidth and viewportheight are actually the width and height of the texture you have bound to the framebuffer. The number of times things like this are just leaving a line out of a constructor... and I expect glViewport would probably throw an error if you try to use 0 for the width or height.

Post lastly, +1 to @Redocdam. Make sure you have checked for OpenGL (including framebuffer completeness) errors
Offline RobinB

JGO Ninja


Medals: 44
Projects: 1
Exp: 3 years


Spacegame in progress


« Reply #4 - Posted 2013-07-31 21:45:25 »

Thank you for the responses.

GL_COLOR_BUFFER_BIT  seems strange indeed, but otherwise the default clearcolor will change to the clearcolor of the framebuffer.
This code is still a bit raw (dont touch what works haha), but thanks for the suggestion, it looks a lil better now.

glLoadIdentity() messes stuff up, i dont know how i can revert this state at Unbind().

As for the errors:
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  
        int framebuffer = EXTFramebufferObject.glCheckFramebufferStatusEXT( EXTFramebufferObject.GL_FRAMEBUFFER_EXT ); 
        switch ( framebuffer ) {
                case EXTFramebufferObject.GL_FRAMEBUFFER_COMPLETE_EXT:
                        break;
                case EXTFramebufferObject.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
                        throw new RuntimeException( "FrameBuffer: " + FBOId
                                        + ", has caused a GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT exception" );
                case EXTFramebufferObject.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
                        throw new RuntimeException( "FrameBuffer: " + FBOId
                                        + ", has caused a GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT exception" );
                case EXTFramebufferObject.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
                        throw new RuntimeException( "FrameBuffer: " + FBOId
                                        + ", has caused a GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT exception" );
                case EXTFramebufferObject.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
                        throw new RuntimeException( "FrameBuffer: " + FBOId
                                        + ", has caused a GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT exception" );
                case EXTFramebufferObject.GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
                        throw new RuntimeException( "FrameBuffer: " + FBOId
                                        + ", has caused a GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT exception" );
                case EXTFramebufferObject.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
                        throw new RuntimeException( "FrameBuffer: " + FBOId
                                        + ", has caused a GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT exception" );
                default:
                        throw new RuntimeException( "Unexpected reply from glCheckFramebufferStatusEXT: " + framebuffer );
        }



I think i need to leave the extension for what it is and aim for opengl 3.0.
Ill rewrite the framebuffer to a cleaner version (from the example of Redocdam).

Only need to find out how to do
1  
2  
3  
int depthRenBuff = EXTFramebufferObject.glGenRenderbuffersEXT();
            // Bind it so we can set it up
           EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, depthRenBuff);

the right way, but i bet there is enough info about it.


Thansk for the help guys Smiley
Offline quew8

JGO Coder


Medals: 29



« Reply #5 - Posted 2013-07-31 21:54:45 »

I would never dissuade someone from rewriting something to be cleaner, but I have to warn you that the only difference with the core, as opposed to the extension, is that you call it with GL30.* rather than EXTFramebufferObject.*

As for reverting the matrix,

1  
2  
3  
4  
5  
6  
7  
8  
9  
//Bind framebuffer
glMatrixMode(GL_PROJECTION);
glPushMatrix(); //Works like pushAttrib but with matrices
glLoadIdentity();

...

glPopMatrix();
//Unbind framebuffer
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.

CopyableCougar4 (22 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 (25 views)
2014-08-16 06:22:17

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

Tekkerue (26 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 (31 views)
2014-08-08 02:01:56

Norakomi (41 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!