Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
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  
  [SOLVED] glMapBuffer  (Read 269 times)
0 Members and 1 Guest are viewing this topic.
Offline trollwarrior1
« Posted 2013-12-01 13:51:35 »

I'm very sorry to be posting a lot of questions, but I can't find almost anything about this problem..

I'm trying to change the data in VBO. The way I'm trying to do it, is glMapBuffer, change the values in that buffer and unmap it. But the problem is that glMapBuffer always returns null. I have read somewhere that this means some kind of an error, but I have no idea what it could be. Here is the code for the entire VBO class.
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  
public class Batch {

   public static final int target = GL_ARRAY_BUFFER;
   
   public int id;
   public int x, y, width, height;
   
   public Batch(int x, int y, int width, int height) {
     
      id = glGenBuffers();
     
      FloatBuffer vertexBuffer = BufferUtils.createFloatBuffer(8);
     
      vertexBuffer.put(x).put(y);
      vertexBuffer.put(x + width).put(y);
      vertexBuffer.put(x + width).put(y + height);
      vertexBuffer.put(x).put(y + height);
      vertexBuffer.flip();
     
      glBindBuffer(target, id);
      glBufferData(target, vertexBuffer, GL_STATIC_DRAW);
     
      glBindBuffer(target, 0);
   }

   
   public void render() {
      glColor3f(1, 1, 0);
     
      glEnableClientState(GL_VERTEX_ARRAY);
     
      glBindBuffer(target, id);
      glVertexPointer(2, GL_FLOAT, 8, 0L);
     
      glDrawArrays(GL_QUADS, 0, 4);
     
      glDisable(GL_VERTEX_ARRAY);
     
      glBindBuffer(target, 0);
   }
   
   public void set(float x, float y, float width, float height) {
     
      glBindBuffer(target, id);
     
      ByteBuffer buffer = glMapBuffer(target, GL_WRITE_ONLY, null);
      System.out.println(buffer);
     
      glBindBuffer(target, 0);
   }
}
Offline quew8

JGO Coder


Medals: 29



« Reply #1 - Posted 2013-12-01 14:47:19 »

After calling glMapBuffer(), call glGetError() which will return an integer error code. If the error is not GL_NO_ERROR, then run it through GLU's gluGetErrorString() method and look up what could be causing that error in the OpenGL docs: http://www.opengl.org/sdk/docs/man4/.

You should be checking for errors anyway (I understand why you aren't - none of the tutorials really tell you to). Not all (in fact very few) OpenGL methods are going to return null if they haven't worked properly. Just check the OpenGL error at the end of each game loop and you'll save yourself a hell of a lot of time.
Offline trollwarrior1
« Reply #2 - Posted 2013-12-01 16:12:44 »

I get an error code 1282, which is invalid operation. I guess I need to somehow change the state of opengl?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline trollwarrior1
« Reply #3 - Posted 2013-12-01 16:29:47 »

Hmm I think the problem was that I wasn't unmapping the buffer. Though I think I was unmapping it at first, and it still didn't work.

Anyway, the fix is to NOT FORGET TO UNMAP the buffer.. It is kinda silly of me Cheesy
Offline quew8

JGO Coder


Medals: 29



« Reply #4 - Posted 2013-12-01 17:27:09 »

If no one made silly mistakes, then we wouldn't need to have all these error codes would we.
Offline trollwarrior1
« Reply #5 - Posted 2013-12-01 17:28:00 »

Ye I know, but I don't like flooding forums with stupid posts like that Sad
Offline quew8

JGO Coder


Medals: 29



« Reply #6 - Posted 2013-12-01 17:35:33 »

But you learnt something from it and that's what this forum exists for.
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.

CogWheelz (15 views)
2014-08-01 22:53:16

CogWheelz (15 views)
2014-08-01 22:51:43

CopyableCougar4 (15 views)
2014-08-01 19:37:19

CogWheelz (19 views)
2014-07-30 21:08:39

Riven (27 views)
2014-07-29 18:09:19

Riven (16 views)
2014-07-29 18:08:52

Dwinin (14 views)
2014-07-29 10:59:34

E.R. Fleming (35 views)
2014-07-29 03:07:13

E.R. Fleming (13 views)
2014-07-29 03:06:25

pw (44 views)
2014-07-24 01:59:36
Resources for WIP games
by CogWheelz
2014-08-01 18:20:17

Resources for WIP games
by CogWheelz
2014-08-01 18:19:50

List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22
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!