Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (528)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (594)
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  
  Cannot use offsets when Pixel Unpack Buffer Object is disabled?  (Read 944 times)
0 Members and 1 Guest are viewing this topic.
Offline JonnyGingerKid

Senior Newbie


Exp: 3 years



« Posted 2014-04-28 05:03:52 »

So I'm trying to learn about FBOs from this tutorial: http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-14-render-to-texture/

This line causes me some problems:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 800, 600, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);

The exception says "Cannot use offsets when Pixel Unpack Buffer Object is disabled", so I tried glEnable(GL_PIXEL_UNPACK_BUFFER)
and then it still gave me the exception. Any help?
Offline quew8

JGO Coder


Medals: 31



« Reply #1 - Posted 2014-04-28 20:26:36 »

The version of that function where the last argument is a long tells OpenGL to fetch the texture data from the currently bound pixel unpack buffer. The last argument being the offset into that PBO to start getting data. When it says that Pixel Unpack Buffer Object is disabled, it means that there is no PBO currently bound, which is equivalent to disabling the pixel unpack buffers.

But my guess is that you are trying to create an empty texture to bind to the FBO right? In which case what you want to do is create an empty ByteBuffer of the appropriate size and pass that to OpenGL. You might be able to pass "null" instead but I seem to recall there being an issue with the LWJGL impl that make that not possible. I might be wrong so you could try it.

So essentially you want to do this (assuming you are using LWJGL)
1  
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 800, 600, 0, GL_RGB, GL_UNSIGNED_BYTE, BufferUtils.createByteBuffer(800 * 600));


or if it works

1  
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 800, 600, 0, GL_RGB, GL_UNSIGNED_BYTE, null);
Offline JonnyGingerKid

Senior Newbie


Exp: 3 years



« Reply #2 - Posted 2014-04-29 04:25:20 »

Ok so I got rid of that color unpack buffer exception thing with your line of code, but now I'm facing another exception. I'll show you the code, then the exception.

The code:

//INIT FBO

//create a blank texture
      int texture = glGenTextures();
      //bind the texture, all future texture calls will modify this texture
      glBindTexture(GL_TEXTURE_2D, texture);
      //give an empty image to OpenGL (the last "0")
      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 800, 600, 0, GL_RGB, GL_UNSIGNED_BYTE, BufferUtils.createByteBuffer(800*600));
      
      //filtering?
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
      
      //create the frame buffer!
      frameBuffer = glGenFramebuffers();
      //bind the framebuffer, all future framebuffer calls will modify this buffer
      glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer);
      
      //set "texture" to color attachment #0
      //glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture, GL_TEXTURE_2D, 0);
       glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
      
      //specify which color attachment the frame buffer will use
      int drawBuffer = GL_COLOR_ATTACHMENT0;
      glDrawBuffers(drawBuffer);

The exception:

Exception in thread "main" java.lang.IllegalArgumentException: Number of remaining buffer elements is 480000, must be at least 1440000. Because at most 1440000 elements can be returned, a buffer with at least 1440000 elements is required, regardless of actual returned element count

The exception occurs at this line:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 800, 600, 0, GL_RGB, GL_UNSIGNED_BYTE, BufferUtils.createByteBuffer(800*600));
Which just happens to be the line you gave me.

Any help?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 834
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #3 - Posted 2014-04-29 06:35:04 »

RGB is 3 bytes per pixel, so your buffer must be 800*600*3 bytes big.

The obscure exception message was written for calls like glGetString, were you have to provide a buffer to be *filled*, but somehow somebody used the same exception message for gl calls that push data, for which the message makes very little sense.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Spasi
« Reply #4 - Posted 2014-04-29 08:26:39 »

You might be able to pass "null" instead but I seem to recall there being an issue with the LWJGL impl that make that not possible. I might be wrong so you could try it.

In order to pass null to a method that has been overloaded with different buffer types, an explicit cast is required to compile, like so:

1  
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 800, 600, 0, GL_RGB, GL_UNSIGNED_BYTE, (ByteBuffer)null);
Offline quew8

JGO Coder


Medals: 31



« Reply #5 - Posted 2014-04-29 22:23:41 »

@JonnyGingerKid sorry about that. My fault. Can't believe I made such a silly mistake.

@Spasi I'm pretty sure you told me that before. Sorry to you too, I'll try and remember the reason in future rather than vague statements that don't say anything.
Offline JonnyGingerKid

Senior Newbie


Exp: 3 years



« Reply #6 - Posted 2014-04-30 04:57:18 »

Hey thanks for that guys, fixed it right up Smiley

Now to begin the adventure of 2D lighting!
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.

PocketCrafter7 (14 views)
2014-11-28 16:25:35

PocketCrafter7 (10 views)
2014-11-28 16:25:09

PocketCrafter7 (11 views)
2014-11-28 16:24:29

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

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

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

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

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

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

Gibbo3771 (28 views)
2014-11-24 19:59:16
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!