I am now confused with the glDrawPixels() function.
I know the function signature is like:
gl.glDrawPixels(int width, int height, format, type, data);
I not not sure how to make format-type-data be consistent.
for instance, I have to use format as GL2.GL_RGB, I am asking
for type=GL2.GL_DOUBLE, GL2.GL_FLOAT, GL2.GL_BYTE, respectively,
What does data look like? how should I wrap and format my data in Java before invoke glDrawPixels() funciton.
First of all, you shouldn’t really use glDrawPixels. It’s a very slow function and in most OpenGL implementation not very optimized. You should use a textured quad instead. But your question also applies to the parameters of glTexImage2D.
So what do these parameters mean. Let’s have a look at the signature of glTexImage2D
internalformatdesignates the format the data will have internally in OpenGL.formatis the format the data inpixelshas and has exactly the same meaning as the parameter of the same name in glDrawPixels. Essentiallyformattells OpenGL how many elements there are to a pixel of data inpixelstypetells OpenGL the type containing a single pixel. Now this is interesting, because its nontrivial.Let’s look at some combinations:
format = GL_BGRA, type = GL_UNSIGNED_INT_8_8_8_8
This tells OpenGL that a pixel consists of 4 elements in the order blue, green, red and alpha, and that all four elements are contained in a single unsigned integer of 32 bits, divided into 4 groups of 8 bits each. You maybe know that color notation of HTML e.g.
#fffffffffor write. Well, this is essentially a 32 bit unsigned int in hexadecimal notation.You could have an array of 32 bit unsigned integers
That would be a 3×3 sized image of a red diamond on white ground.
format = GL_RGB, type = GL_UNSIGNED_BYTE
In this case we tell OpenGL that there are 3 elements, red, green and blue, to a pixel and because the type has no explicit subsizes indicated, that each element of such type contains one color element of the pixel
Our red diamond would look like this then
format = GL_RGBA, type = GL_FLOAT (or GL_DOUBLE)
In this case each element of a pixel is a individual float, in the range [0; 1]. The diamond would then look like
For GL_DOUBLE it looks exactly the same but with
doubleinstead offloat.I hope you now get the basic gist