Results 1 to 4 of 4

Thread: Point VBO

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2014
    Posts
    25

    Point VBO

    Hi folks,

    just looking for a bit of education on vertex buffers. I'm trying to draw a bunch of points via a vbo - firstly, is this fine? If yes..

    I'm setting up my vbo in a custom function. The setup looks a little like this:

    Code :
    void My_Window::SetupBufferObject(int Size)
    {
    	GLuint buffer = NULL;
     
    	// POSITION
    	glGenBuffers(1,&buffer);
    	PointVBO[Size][0] = buffer;
    	glBindBuffer(GL_ARRAY_BUFFER,buffer);
    	glBufferData(GL_ARRAY_BUFFER,sizeof(pointPos),pointPos,GL_DYNAMIC_DRAW);
    	glBufferSubData(GL_ARRAY_BUFFER,NULL,sizeof(pointPos),pointPos);
     
    	// COLOUR
    	glGenBuffers(1,&buffer);
    	PointVBO[Size][1] = buffer;
    	glBindBuffer(GL_ARRAY_BUFFER,buffer);
    	glBufferData(GL_ARRAY_BUFFER,sizeof(pointCol),pointCol,GL_DYNAMIC_DRAW);
    	glBufferSubData(GL_ARRAY_BUFFER,NULL,sizeof(pointCol),pointCol);
    }

    For the purpose of the above, PointVBO is just a vector array of int's used for holding ids of buffers, and Size is set to 1. I'm confident the data is also good - I can draw the points manually each frame via a for loop, using pointPos and pointCol, and everything appears to be in order as far as that's concerned. At this stage, does that look alright?

    The draw calls themselves is where I don't think I'm understanding things well. I've tried quite a few variations of the following, but none are getting me anywhere. I'll post where it's at now so you can at least see something I've tried with:

    Code :
    void My_Window::DrawGL(void)
    {
    	... // setup/begin draw
     
    	glBindBuffer(GL_ARRAY_BUFFER,PointVBO[1][0]);
    	glEnableClientState(GL_VERTEX_ARRAY);
    	glVertexPointer(200*100*3,GL_BYTE,3*sizeof(char),&pointPos[0]);
     
    	glBindBuffer(GL_ARRAY_BUFFER,PointVBO[1][1]);
    	glEnableClientState(GL_COLOR_ARRAY);
    	glColorPointer(200*100*3,GL_BYTE,3*sizeof(char),0);
     
    	glDrawArrays(GL_POINTS,0,200*100);
    	glDisableClientState(GL_COLOR_ARRAY);
    	glDisableClientState(GL_VERTEX_ARRAY);	
     
    	... // draw other/end draw
    }

    I'm trying to use separate buffers for the positioning and colours so that I can dig into those at some stage in the future and work on them individually. Is this where a VAO might come in handy?

    What and where am I missing things here? Cheers,

    WP.

  2. #2
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,678
    Code :
    	glBufferData(GL_ARRAY_BUFFER,sizeof(pointPos),pointPos,GL_DYNAMIC_DRAW);
    	glBufferSubData(GL_ARRAY_BUFFER,NULL,sizeof(pointPos),pointPos);

    This is redundant. glBufferData already took a pointer to the data you wanted to upload. You don't need to call glBufferSubData to upload data you already uploaded.

    Also, NULL is not the same thing as 0.

    But these aren't your problems.

    Code :
    glVertexPointer(200*100*3,GL_BYTE,3*sizeof(char),&pointPos[0]);

    There are many things wrong with this.

    The first parameter is not the size of the array. It's the number of components in one vertex. If you're transmitting two-dimensional data, then you would put 2 there. If your points are 3-dimensional (X, Y and Z), you put 3 there. Since you set your stride to be 3 * sizeof(char) (which should be 3 * sizeof(GLbyte)), I'm guessing every 3 bytes represents the position of a single point. So you would set this to 3.

    Equally importantly, when a buffer object is bound to GL_ARRAY_BUFFER, the meaning of the last parameter changes. It is no longer a pointer value. It is instead a byte offset from the beginning of the buffer bound to GL_ARRAY_BUFFER at the time this function was called. Since your vertex data starts at the beginning of that buffer, you should set it to zero.

    Or, since the parameter's type is still a pointer, even though OpenGL will treat it as an integer byte offset, it should more accurately be reinterpret_cast<void*>(0);

    I see you did your glColorPointer call correctly with regard to the zero (though without the reinterpret_cast), so this is probably just a copy-and-paste bug. But the size is also still wrong.

    Also, since your size was not 2, 3, or 4, you should have gotten an OpenGL error. You should always check your errors when things start going wrong.

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2014
    Posts
    25
    My apologies if this appears twice, I seem to be having an few issues with this website and IE.

    Thanks Alfonse, that's cleared a few things up. I've made a few small changes, mainly with the data type, and the point positions seem fine. But I'm still having an issue with the colour. Apart from one pixel, they are all black. These are the draw lines associated with it:

    Code :
    	// in draw function
    	glBindBuffer(GL_ARRAY_BUFFER,PointVBO[1][1]);
    	glEnableClientState(GL_COLOR_ARRAY);
    	glColorPointer(3,GL_UNSIGNED_BYTE,0,reinterpret_cast<void*>(0));

    I've placed error checking at the end of each line, but no errors are reported (removed in above to save some reading). The colour data is coming from an unsigned *char container. Is that the cause of the black wash out?

    WP.

  4. #4
    Junior Member Newbie
    Join Date
    Jul 2014
    Posts
    25
    Alrighty, I've managed to fix the colour issue. It had something to do with the colour pixel values themselves. I converted them to floating point, and all appears to be working well.

    Just while I'm here, something is wonky with using the reply link and IE on this site. It isn't working for me every first time I use it. I get the reply edit text area, but hitting the 'Post Quick Reply' button never submits the reply on the first go. Should I report this somewhere?

    WP.

Similar Threads

  1. What are: floating-point and fixed-point systems ?
    By uwi2k2 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-20-2012, 11:39 AM
  2. [Ray vs AABB] exit point knowing entry point
    By _blitz in forum OpenGL: General
    Replies: 2
    Last Post: 12-08-2011, 12:03 PM
  3. Convert mouse point to box2d point in opengl
    By Apoptyzm in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-16-2009, 01:25 PM
  4. Fastest way to compute 2D view point from 3D point?
    By robosport in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 10-15-2003, 11:45 AM
  5. How do you draw wire frame lines from point to point?
    By HAMCircuitsWillBearMyName in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-27-2001, 08:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean