Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (526)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (593)
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  
  Debugging OpenGL code  (Read 1133 times)
0 Members and 1 Guest are viewing this topic.
Offline SHC
« Posted 2014-03-25 14:10:34 »

I'm writing a Batcher currently and having nothing displayed on the screen. I haven't understood what's the problem, I've rewritten the class more than a 20 times and still the same result. So I've tried using
glGetError()
and put calls to it after every call to a opengl function and set break-points on those instances. The output said that there are errors when I'm updating the VBOs, so here is my code where I update my VBOs.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
glBindBuffer(GL_ARRAY_BUFFER, vboVertID);
checkForErrors();
glBufferSubData(GL_ARRAY_BUFFER, 0, vBuffer);
checkForErrors();// Unacceptable value, Specified operation is not allowed in current state
       
glBindBuffer(GL_ARRAY_BUFFER, vboNormID);
checkForErrors();// Numeric argument is out of range
glBufferSubData(GL_ARRAY_BUFFER, 0, nBuffer);
checkForErrors();
       
glBindBuffer(GL_ARRAY_BUFFER, vboColID);
checkForErrors();// Numeric argument is out of range
glBufferSubData(GL_ARRAY_BUFFER, 0, cBuffer);
checkForErrors();
       
glBindBuffer(GL_ARRAY_BUFFER, vboTexID);
checkForErrors();// Numeric argument is out of range
glBufferSubData(GL_ARRAY_BUFFER, 0, tBuffer);
checkForErrors();

And my method to print the error messages is

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
public void checkForErrors()
{
    int error = GL_NO_ERROR;
       
    while ((error = glGetError()) != GL_NO_ERROR)
    {
        switch (error)
        {
            case GL_INVALID_ENUM:
                System.err.println("An unacceptable value is specified for an enumerated argument.");
                break;
            case GL_INVALID_VALUE:
                System.err.println("A numeric argument is out of range.");
                break;
            case GL_INVALID_OPERATION:
                System.err.println("The specified operation is not allowed in the current state.");
                break;
            default:
                System.err.println("Unknown OpenGL Error");
        }
    }
}

I'm now confused on where the error is. The complete class is here.

Thanks.

Offline Grunnt

JGO Kernel


Medals: 94
Projects: 8
Exp: 5 years


Complex != complicated


« Reply #1 - Posted 2014-03-25 14:34:53 »

What is the precise output you get?

Also, you may get better error descriptions using the following method (borrowed from ra4king):
1  
2  
3  
4  
5  
public static void checkGLError(String event) {
      int error;
      if((error = glGetError()) != GL_NO_ERROR)
         throw new RuntimeException("OpenGL Error during " + event + ": " + gluErrorString(error));
   }

Offline SHC
« Reply #2 - Posted 2014-03-25 14:48:14 »

Here is the output from it.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
glBindBuffer(GL_ARRAY_BUFFER, vboVertID);
checkForErrors("L120"); // Invalid enum, Invalid operation
glBufferSubData(GL_ARRAY_BUFFER, 0, vBuffer);
checkForErrors("L122"); // Invalid value

glBindBuffer(GL_ARRAY_BUFFER, vboNormID);
checkForErrors("L125");
glBufferSubData(GL_ARRAY_BUFFER, 0, nBuffer);
checkForErrors("L127"); // Invalid value

glBindBuffer(GL_ARRAY_BUFFER, vboColID);
checkForErrors("L130");
glBufferSubData(GL_ARRAY_BUFFER, 0, cBuffer);
checkForErrors("L132"); // Invalid value

glBindBuffer(GL_ARRAY_BUFFER, vboTexID);
checkForErrors("L135");
glBufferSubData(GL_ARRAY_BUFFER, 0, tBuffer);
checkForErrors("L137"); // Invalid value

Dunno why does my
glBindBuffer()
call returns
GL_INVALID_ENUM
or
GL_INVALID_OPERATION

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Grunnt

JGO Kernel


Medals: 94
Projects: 8
Exp: 5 years


Complex != complicated


« Reply #3 - Posted 2014-03-25 17:23:16 »

That is source code, right? Or am I missing something? I sure does not look like any output.

Offline theagentd

« JGO Bitwise Duke »


Medals: 361
Projects: 2
Exp: 8 years



« Reply #4 - Posted 2014-03-25 17:31:42 »

Enable OpenGL debug mode.
1  
2  
            Display.create(new PixelFormat(), new ContextAttribs().withDebug(true));
            glDebugMessageCallbackARB(new ARBDebugOutputCallback());

Myomyomyo.
Offline SHC
« Reply #5 - Posted 2014-03-26 02:40:33 »

@Grunnt
Sorry for not mentioning that I've commented the errors on the line in the source based on the output. Here is the actual output.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
L120: Invalid enum
L122: Invalid value
L127: Invalid value
L132: Invalid value
L137: Invalid value
L120: Invalid operation
L122: Invalid value
L127: Invalid value
L132: Invalid value
L137: Invalid value
L120: Invalid operation
L122: Invalid value
L127: Invalid value
L132: Invalid value
L137: Invalid value
... same being repeated ...

@theagentd

That didn't work out. It said that "the function is not supported" on the glDebugMessageCallbackARB line.

Offline theagentd

« JGO Bitwise Duke »


Medals: 361
Projects: 2
Exp: 8 years



« Reply #6 - Posted 2014-03-26 08:54:07 »

It's impossible to say what the problem is with just this code.

1. Look at the official documentation pages for the functions you're calling and you'll see what the different errors mean. From http://www.opengl.org/sdk/docs/man2/xhtml/glBufferSubData.xml:
Quote
GL_INVALID_VALUE is generated if offset or size is negative, or if together they define a region of memory that extends beyond the buffer object's allocated data store.

2. You should always call glGetError() BEFORE what you're trying to debug as well as after to ensure that no error was already present when the function was called. Remember that if an error occurs, glGetError() will be locked to that error code until you clear it with glGetError(). I suspect this is why you're detecting a "Invalid enum" error on glBindBuffer() since GL_ARRAY_BUFFER is a valid enum.

That didn't work out. It said that "the function is not supported" on the glDebugMessageCallbackARB line.
Either you're developing on an Intel card or you have really outdated drivers for your Nvidia/AMD card. It's a good idea to get this working as it gives much more detailed information about errors.

Myomyomyo.
Offline SHC
« Reply #7 - Posted 2014-03-26 09:14:55 »

@theagentd

Yes I've added calls to
checkForErrors()
before and after each opengl call. I've added them even before creation of buffers too. The errors only start to appear when the
end()
method is called on the batcher where I update the buffers and render them.

Either you're developing on an Intel card or you have really outdated drivers for your Nvidia/AMD card.

My card is NVIDIA GeForce 210 (I know it's old, saving my pocket money for a new card) and I'm using a hackintosh so I'm limited to compatibility mode (OpenGL 2.1 but supports 95% of OpenGL 3.3 functions as well). The driver version is 310.84, is old too, but there isn't a new release for mac. Any ideas on what to do?

Offline trollwarrior1
« Reply #8 - Posted 2014-03-26 09:19:44 »

why is drawarrays (something, something, vertexamount*9)
I thought it needed (something, something, vertexmount)
Offline SHC
« Reply #9 - Posted 2014-03-26 09:22:26 »

why is drawarrays (something, something, vertexamount*9)
I thought it needed (something, something, vertexmount)

I copied it from a previous one where
vertexamount
was
model.getFaces()
. Didn't work with
vertexamount
either.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline trollwarrior1
« Reply #10 - Posted 2014-03-26 09:28:03 »

hmmmmmmmm
The only last suggestion I have from my experience is look at the very basics. Most of my errors are really small things at lowest level of my program. Sometimes I spend whole day trying to solve a bug and at the end of the day I go check basic constructor which is supposed to set things, but it doesn't.

What I mean is try using quads, they are not 'best' but for 2d game they don't make any difference.
Also try not using any things like shaders, framebuffers and all the other stuff that isn't necessary for rendering basic shapes.
You might just wanna try to write a basic spritebatcher which only handles vertices.
Offline theagentd

« JGO Bitwise Duke »


Medals: 361
Projects: 2
Exp: 8 years



« Reply #11 - Posted 2014-03-26 10:34:39 »

@theagentd

Yes I've added calls to
checkForErrors()
before and after each opengl call. I've added them even before creation of buffers too. The errors only start to appear when the
end()
method is called on the batcher where I update the buffers and render them.

Either you're developing on an Intel card or you have really outdated drivers for your Nvidia/AMD card.

My card is NVIDIA GeForce 210 (I know it's old, saving my pocket money for a new card) and I'm using a hackintosh so I'm limited to compatibility mode (OpenGL 2.1 but supports 95% of OpenGL 3.3 functions as well). The driver version is 310.84, is old too, but there isn't a new release for mac. Any ideas on what to do?

The only thing left then is to look at the documentation of each of your failing methods and see what those errors are caused by. I'm pretty sure debug mode doesn't work on Macs regardless of profile.

Myomyomyo.
Offline SHC
« Reply #12 - Posted 2014-03-30 03:08:08 »

Found this on the docs of
glBindBuffer()


Quote
While a non-zero buffer object name is bound, GL operations on the target to which it is bound affect the bound buffer object, and queries of the target to which it is bound return state from the bound buffer object. While buffer object name zero is bound, as in the initial state, attempts to modify or query state on the target to which it is bound generates an GL_INVALID_OPERATION error.

I can't understand it properly. Can you please explain what it means to me?

Online The Lion King
« Reply #13 - Posted 2014-03-30 04:33:30 »

It means that all relevant buffer operations will affect the bound buffer. Binding 0 is the same as binding nothing or null (same as having nothing bound). If 0 is bound then any operations will throw a GL_INVALID_OPERATION error. Initially 0 is bound.

"You have to want it more than you want to breath, then you will be successful"
Offline SHC
« Reply #14 - Posted 2014-03-30 05:26:57 »

So, it means that 0 is the currently bound vbo. I've been passing
vboVertID
to the call, dunno why 0 is bound still. I've also ensured that the value of the vbo is not 0, it's 1 in the debugger and I've also generated the buffer.

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 (71 views)
2014-11-26 15:22:04

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

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

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

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

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

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

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

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

digdugdiggy (55 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!