glTexSubImage2D

Hey guys

i have few simple question which aren’t quite clear to me.

  1. when i use glTexSubImage2D , the last param is a pointer to my points… since im using cuda, my points

are allocated over the device , hence i can’t use the traditional way of attaching the “pointer”

because it’s pointing at an “unknown” place…

is the answer is to forword NULL param instead of the pointer and before that command use glbindbuffer

to load the allocated device over the cuda like so :

glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer);

glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, MAXX, MAXY, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

the following example works … but im not sure if it’s the right and correct way .

2.i saw the following code to init a buffer

glGenBuffers(1, buffer);

    glBindBuffer(GL_PIXEL_PACK_BUFFER, *buffer); 

    glBufferData(GL_PIXEL_PACK_BUFFER, MAXX*MAXY*4, NULL, GL_DYNAMIC_DRAW);

a MAXXMAXY4 uninitialized points buffer was declared , my guess that the 4 stands for X Y Z W coords…

now for printing the following lines were used :

glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer);

glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, MAXX, MAXY, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

my question is , how does the cpu knows that im using 4 cords system? (maybe i want to use only x,y which is only 2 cords system)

thanks!

If I understood you question correctly, the CPU knows because of GL_RGBA. This param tells OpenGL how to access the buffer. When you alloc the data you set MAXXMAXXY4, this is works like a malloc, but on GPU. When you set GL_RGBA, you are telling OpenGL to access a buffer with dimensions MAXX, MAXY where each position has informations about 4 channels of color (RGBA).

Thanks for your answer… so the multiple by 4 actually represents the RGBA properties of each pixel?

i mean what doesn’t look clear to me is that i paint on the screen using pixels… but where are the X Y Z points are saved?

When defining the buffer, with glBufferData you are allocating memory in GPU for the buffer bound on glBindBuffer. Note you’re passing NULL as the parameter for data. This means you are just reserving space. How this space is interpreted is up to you to tell OpenGL. Calling glTexSubImage2D with a buffer bound tells OpenGL to use that buffer as a texture image. If the buffer do not represent a displayable image, you won’t anything that makes sense on the screen.

In order to display 3D objects, you need to store 3D data on the buffer changing the NULL parameter of glBufferData to some pointer containing the data. In order to draw this points, one way is to use glDrawArrays or glDrawElements. Take a look at the reference pages for this functions and take a look at VBOs.

glTexSubImage2D

glBufferData

Vertex Buffer Objects

glDrawArrays

glDrawElements

PS.: I suggest you to use the OpenGL forums for this kind of question.