Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (804)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (868)
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  
  [OpenGL] DrawElements - element array buffer object disabled? [SOLVED]  (Read 5124 times)
0 Members and 1 Guest are viewing this topic.
Offline Hermasetas

Senior Devvie


Medals: 6
Projects: 2
Exp: 7 years


I do gamez, yes!


« Posted 2014-04-26 14:47:57 »

Hi guys!

Yet again opengl is giving me a lot of attitude and I can't figure out why...

I am trying to draw a rectangle using 2 triangles drawn with glDrawElements.
No textures just color.
I am in the same program drawing a lot of rectangles with texturing and that is still working but a simple rectangle does not work...

When I use the code below I get the error below the code, saying that "element array buffer object is disabled".
If I try to use glDrawElements with a shortbuffer directly I get the exact opposite error: "Element array buffer object is enabled".

I have made sure that all the vbo-IDs are not -1. So they are there...

Also it worked when I used glDrawArrays, but it stopped working when I converted to glDrawElements.

This truly confuse me so i hope that someone else can spot the problem Smiley
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  
public void render()
{  
   //If there is nothing to render return
   if(numberOfVerticies == 0)
      return;
   
   glUseProgram(shaderProgramID);      
   
   //Send the data to the vertex-vbo
   buffer.flip();
   glBindBuffer(GL_ARRAY_BUFFER, vboID);
   glBufferData(GL_ARRAY_BUFFER, buffer, GL_DYNAMIC_DRAW);
   
   //Send the indecies to the index-vbo
   indexBuffer.flip();
   glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ivboID);
   glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexBuffer, GL_DYNAMIC_DRAW);
   
   //Bind the vao
   glBindVertexArray(vaoID);
   
   //Draw the triangles
   glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
   
   //Reset the batcher
   buffer.clear();
   indexBuffer.clear();
   numberOfVerticies = 0;
}


1  
2  
3  
4  
5  
6  
7  
8  
9  
org.lwjgl.opengl.OpenGLException: Cannot use offsets when Element Array Buffer Object is disabled
   at org.lwjgl.opengl.GLChecks.ensureElementVBOenabled(GLChecks.java:105)
   at org.lwjgl.opengl.GL11.glDrawElements(GL11.java:1117)
   at graphics.ShapeBatcher.render(ShapeBatcher.java:325)
   at graphics.SpriteBatcher.checkMode(SpriteBatcher.java:471)
   at graphics.SpriteBatcher.render(SpriteBatcher.java:428)
   at startMenu.StartMenu.render(StartMenu.java:106)
   at stateBasedGame.StateBasedGame.start(StateBasedGame.java:49)
   at Main.main(Main.java:53)
Offline theagentd
« Reply #1 - Posted 2014-04-26 14:51:47 »

How is your VAO set up?

Myomyomyo.
Offline Hermasetas

Senior Devvie


Medals: 6
Projects: 2
Exp: 7 years


I do gamez, yes!


« Reply #2 - Posted 2014-04-26 14:54:36 »

Like this:

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  
private void setupBuffers()
{
   //Setup VAO and activate the first 2 attributes
   vaoID = glGenVertexArrays();
   glBindVertexArray(vaoID);
   glEnableVertexAttribArray(0);
   glEnableVertexAttribArray(1);
         
   //Setup vertex-VBO
   vboID = glGenBuffers();
   glBindBuffer(GL_ARRAY_BUFFER, vboID);
   
   //Setup VAO pointers
   int bytesPerFloat = 4;
   int numberOfVertecies = 2;
   int numberOfColors = 4;
         
   int bytesPerVertex = (numberOfVertecies + numberOfColors) * bytesPerFloat;
   
   //Giv VAO'en vertex-VBO'en på index 0
   glVertexAttribPointer(0, 2, GL_FLOAT, false, bytesPerVertex, 0);
         
   //Giv VAO'en color-VBO'en på index 1
   int colorOffset = numberOfVertecies * bytesPerFloat;
   glVertexAttribPointer(1, 4, GL_FLOAT, false, bytesPerVertex, colorOffset);
   
   //Setup index-VBO
   ivboID = glGenBuffers();
}


But as I said it worked fine with glDrawArrays Huh
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline theagentd
« Reply #3 - Posted 2014-04-26 19:01:56 »

You need to bind the index buffer when creating your VAO. The index buffer binding is stored in the VAO.

Myomyomyo.
Offline Hermasetas

Senior Devvie


Medals: 6
Projects: 2
Exp: 7 years


I do gamez, yes!


« Reply #4 - Posted 2014-04-27 00:46:11 »

Hey that worked! Cheesy

Also I had to bind the vao before the index-buffer when rendering.
I did not do this when rendering with my spritebatcher, but I guess it becomes an issue when you have multiple vaos Tongue

Thank you very much!
I would never have figured that out  Smiley
Offline theagentd
« Reply #5 - Posted 2014-04-27 01:49:53 »

Lots of good info here: http://en.wikipedia.org/wiki/Vertex_Buffer_Object

Myomyomyo.
Pages: [1]
  ignore  |  Print  
 
 

 
Riven (579 views)
2019-09-04 15:33:17

hadezbladez (5504 views)
2018-11-16 13:46:03

hadezbladez (2398 views)
2018-11-16 13:41:33

hadezbladez (5766 views)
2018-11-16 13:35:35

hadezbladez (1220 views)
2018-11-16 13:32:03

EgonOlsen (4660 views)
2018-06-10 19:43:48

EgonOlsen (5681 views)
2018-06-10 19:43:44

EgonOlsen (3196 views)
2018-06-10 19:43:20

DesertCoockie (4094 views)
2018-05-13 18:23:11

nelsongames (5114 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04: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!