Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (568)
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  
  lwjgl vbo fatal error ??  (Read 725 times)
0 Members and 1 Guest are viewing this topic.
Offline trollwarrior1
« Posted 2014-03-21 09:15:51 »

I have been looking at dis code for more than an hour and its getting annoying. I have generated a nice stack of fatal error logs already. Maybe someone can help meh? Cry

.render();

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  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
public class Mesh3D {

   public static int target = GL_ARRAY_BUFFER;
   
   public int vertexHandle;
   public int size;

   private int position = 0;
   private float[] vertices;

   public Mesh3D(int size) {
      vertexHandle = glGenBuffers();
      this.size = size;
      vertices = new float[size * 3];
   }

   public void put(float x, float y, float z) {
      vertices[position++] = x;
      vertices[position++] = y;
      vertices[position++] = z;
   }
   
   public void put(float x, float y, float z, float width, float height){
      put(x, y, z);
      put(x+width, y, z);
      put(x+width, y+height, z);
      put(x, y+height, z);
   }

   public void upload() {
      FloatBuffer buffer = BufferUtils.createFloatBuffer(size*3);
      buffer.put(vertices);
      buffer.flip();
     
      glBindBuffer(target, vertexHandle);
      glBufferData(target, buffer, GL_STATIC_DRAW);
   }

   public void render() {
     
      glEnableClientState(GL_VERTEX_ARRAY);
     
     
      glBindBuffer(target, vertexHandle);
      glVertexPointer(3, GL_FLOAT, 3 << 2, 0l);
      glBindBuffer(target, 0);

      // FATAL ERROR OCCURS ON NEXT LINE
     glDrawArrays(GL_QUADS, 0, size);
     
     
      glDisableClientState(GL_VERTEX_ARRAY);
     
   }
   
   public void clear() {
   }

}
Offline The Lion King
« Reply #1 - Posted 2014-03-21 09:47:43 »

1  
glVertexPointer(3, GL_FLOAT, 3 << 2, 0l);

should be
1  
glVertexPointer(3, GL_FLOAT, 0, 0L);



the integer 3 in bits looks like this

0000 0000 0000 0011

when you do 3 << 2, you shift the bits 2 spaces to the left.

this turns 3 into

0000 0000 0000  1100

which is the number 12, this is giving you the wrong stride value

[edit]
 i wrote 24 instead of 12, fixed it

[double edit]

sorry i'm wrong here never even thought of doing. i always just multiply by 4

"You have to want it more than you want to breath, then you will be successful"
Offline trollwarrior1
« Reply #2 - Posted 2014-03-21 09:50:36 »

I believe it is stride in bytes, but either way it doesn't work if I put 0, 3, or 18. If stride is messed up, it would only not display at all or render something glitchy.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline The Lion King
« Reply #3 - Posted 2014-03-21 09:57:35 »

do you ever put values into verticies?

Try printing out the values of verticies.

"You have to want it more than you want to breath, then you will be successful"
Offline trollwarrior1
« Reply #4 - Posted 2014-03-21 09:58:57 »

do you ever put values into verticies?

Try printing out the values of verticies.

It doesn't matter, they are 0 by default, which shouldn't cause any problem, I will make sure to put them manually and try though.
Offline The Lion King
« Reply #5 - Posted 2014-03-21 10:02:13 »

Sorry had a lapse between different languages, your right, having values shouldn't cause any errors
1  
2  
3  
      verticies = new float[size * 3];
      ...
      glDrawArrays(GL_QUADS, 0, size);


if you put the parameter of size as 4, it will make a buffer with 12 vertices and try to draw 4 quads (which needs 16 vertices)

"You have to want it more than you want to breath, then you will be successful"
Offline trollwarrior1
« Reply #6 - Posted 2014-03-21 10:05:20 »

Sorry had a lapse between different languages, your right, having values shouldn't cause any errors
1  
2  
3  
      verticies = new float[size * 3];
      ...
      glDrawArrays(GL_QUADS, 0, size);


if you put the parameter of size as 4, it will make a buffer with 12 vertices and try to draw 4 quads (which needs 16 vertices)

size*3 means each vertex is composed of xyz. That means that vertices.length/3 = verticesAmount
Offline The Lion King
« Reply #7 - Posted 2014-03-21 10:08:08 »

In that case make sure that number is divisible by 4. Thats all i got, taking a look at it.

Sorry , Its 3 am and i'm sorta burnt out, shouldnt be trying to answer questions right now. Maybe someone better than me can help you. Good luck Smiley

"You have to want it more than you want to breath, then you will be successful"
Offline orange451

Senior Member


Medals: 7
Projects: 1
Exp: 4 years


Your face. Your ass. What's the difference?


« Reply #8 - Posted 2014-03-21 13:32:39 »

Just a heads up (I learned this the hard way)
1  
glVertexPointer
is deprecated, IE, it doesn't work in "core" more (OpenGL3+).

Normally this wouldn't be an issue--If you're on a PC and are on the default compatibility mode, you can use both deprecated and non-deprecated methods without worrying. If you're on a mac however... and if you use compatibility mode (on my default), you can't use ANY OpenGL3+ methods. If you turn off compatibility mode, and turn on core mode, you can't use anything but OpenGL3+.

This method has been replaced with:
1  
GL20.glVertexAttribPointer()


If you want an example on it:
http://www.lwjgl.org/wiki/index.php?title=The_Quad_with_Projection,_View_and_Model_matrices

Sorry if I'm being "that guy" that is trying to get you to do a different method of things, rather than solving your problem directly... But getting rid of deprecated methods really helps in the long run!



--
[EDIT]
If you want help with your current problem...
(going off of what lion king started)

If you use a size of "GL11.GL_FLOAT", then that means there is 4 bytes per float. Since you are only using vertices which have 3 components, the stride then is 3 * 4.

Since the vertices are the first thing you're "setting up" in your VAO, the position should be 0.

So:
1  
glVertexPointer(3, GL_FLOAT, 12, 0L);




--
[EDIT 2]
glancing through your code, I feel like your drawArrays should be:
1  
 glDrawArrays(GL_QUADS, 0, vertices.length);




--
[EDIT 3]
I wouldn't use quads in a custom mesh class... It limits you greatly in what you can have meshes look like... I am not sure if my above code will work w/ quads, I know it'll work with triangles...
If you do end up using triangles, you second put method could be written this way:
1  
2  
3  
4  
5  
6  
7  
8  
public void put(float x, float y, float z, float width, float height){
   put(x, y, z);
   put(x+width, y, z);
   put(x+width, y+height, z);
   put(x+width, y+height, z);
   put(x, y+height, z);
   put(x, y, z);
}

Working on a nice FPS in lwjgl Smiley http://i.imgur.com/q4uFqBS.png
Feel free to message me if you're interested!
Offline trollwarrior1
« Reply #9 - Posted 2014-03-21 15:16:27 »

@orange

I changed my code to gl20 glvertexattribpointer, but the fatal error doesn't go away no matter what I try Cheesy
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline orange451

Senior Member


Medals: 7
Projects: 1
Exp: 4 years


Your face. Your ass. What's the difference?


« Reply #10 - Posted 2014-03-21 15:43:39 »

Can I see your up-to-date version of the class AND your implementation of it?

Working on a nice FPS in lwjgl Smiley http://i.imgur.com/q4uFqBS.png
Feel free to message me if you're interested!
Offline The Lion King
« Reply #11 - Posted 2014-03-21 17:30:08 »

dunno if this will help, but i wrote up this quick (working) program
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
   {   
      float[] test =
         { -1f, -1f,
            0f, 1f,
            1f, -1f
         };
      FloatBuffer buf = BufferUtils.createFloatBuffer(6);
      buf.put(test);
      buf.rewind();

      vboID = GL15.glGenBuffers();
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID);
      GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buf, GL15.GL_STATIC_DRAW);
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
   }
   public void draw()
   {
      GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID);
      GL11.glVertexPointer(2, GL11.GL_FLOAT, 8, 0);
      GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 3);
      GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
   }

"You have to want it more than you want to breath, then you will be successful"
Offline trollwarrior1
« Reply #12 - Posted 2014-03-21 20:54:37 »

@lion king

Mhmmmmm. Your code also crashes.. I will try breaking down my program into the smallest size possible to see if i'm maybe doing something wrong with states, will also try to check for opengl error.

edit--
It seems that I don't get fatal error if I don't do glViewport.

Something tells me that glu.gluperspective and gl11.glviewport dont mix together Cheesy
It seems that after I removed viewport call everything magically works..
Offline trollwarrior1
« Reply #13 - Posted 2014-03-22 06:51:31 »

Ok it seems the problem had something to do with my custom shaders. I was probably overwriting vertex attribute indices.
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.

Pippogeek (41 views)
2014-09-24 16:13:29

Pippogeek (32 views)
2014-09-24 16:12:22

Pippogeek (22 views)
2014-09-24 16:12:06

Grunnt (47 views)
2014-09-23 14:38:19

radar3301 (30 views)
2014-09-21 23:33:17

BurntPizza (65 views)
2014-09-21 02:42:18

BurntPizza (37 views)
2014-09-21 01:30:30

moogie (44 views)
2014-09-21 00:26:15

UprightPath (53 views)
2014-09-20 20:14:06

BurntPizza (55 views)
2014-09-19 03:14:18
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!