Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbish Question regarding texturing VBOs



Thank you very much Stefan - this has helped point me in the right direction. Im still having some issues however (again, apologies if most of this is self evident - this is way beyond my normal hobbying around - I appreciate anyone taking the time to look at this). I would love some more guidance on this subject. Here is what I am attempting in a bit more detail ( taken from 10.5s Quart Composer example patch GLHeighField)

I am generating two VBOs and allocating memory for them : (kSize is a constant, say 128/256)

/* Create VBOs */
glGenBuffers(2, &_vertexBuffer); // change this to two buffers - one for VBO and the other for Texture Coords
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);


glBufferData(GL_ARRAY_BUFFER, kSize * kSize * 4 * sizeof(GLfloat), NULL, GL_DYNAMIC_COPY);
glBindBuffer(GL_ARRAY_BUFFER, 1); // for textures


glBufferData(GL_ARRAY_BUFFER, kSize * kSize * 4 * sizeof(GLfloat), NULL, GL_DYNAMIC_COPY);
glBindBuffer(GL_ARRAY_BUFFER, 0); // for verts



I Draw to them via

// for textures
glBegin();
blah blah
glEnd();

glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, _vertexBuffer);
glReadPixels(0, 0, kSize, kSize, GL_RGBA, GL_FLOAT, NULL);  
glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 1); // use the second buffer for texturing. yay?


// for verts
glBegin();
blah blah
glEnd();

/* Copy the rendered pixels into the VBO */
glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, _vertexBuffer);
glReadPixels(0, 0, kSize, kSize, GL_RGBA, GL_FLOAT, NULL);
glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); // use the first buffer for verts

Now, I am attempting to draw the vertex buffer with glDrawElements, using both the vert buffer and the pseudo texture buffer vert hack thingy (ahem :) )
glEnableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
glVertexPointer(4, GL_FLOAT, 0, NULL);
glBindBuffer(GL_ARRAY_BUFFER, 0);

glEnableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
glTexCoordPointer(4, GL_FLOAT, 0, NULL);
glBindBuffer(GL_ARRAY_BUFFER, 1);


glDrawElements(GL_TRIANGLES, (kSize - 1) * (kSize - 1) * 6, GL_UNSIGNED_INT, _indices);

glDisableClientState(GL_VERTEX_ARRAY);


Again, this is just me attempting to reverse engineer the example code and infer proper syntax. Ive consulted google and checked up on some other fora, however I am still at a loss - so I do appreciate any other guidance. Thanks in advance (again).

On Oct 31, 2007, at 5:54 PM, Stefan Dösinger wrote:

Am Mittwoch, 31. Oktober 2007 21:14:25 schrieb vade:

So, in short, how does one specify texture coordinates for the
glDrawElements without using interleaved buffers? Apologies if this is
self evident, this is a bit deeper into OpenGL than I normally go.
If I understand it correctly, using two vbos might be helpful: Create one vbo
with position data, and one with the texture coordinates, then load the
vertex streams like this:

glBindBuffer(positionVBO);
glVertexPointer(...);
glBindBuffer(textureVBO);
glTexCoordPointer(...);

It is no issue to source two vbos, and glBindBuffer is designed to be cheap to
allow exactly what the code above does. In this case you can have different
strides of the elements in both buffers and don't have to care about the
position data when rendering out your texcoords. The texcoords can be packed
in any way you want them.

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Mac-opengl mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/mac-opengl/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.