LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: rasirdas on July 24, 2006, 14:02:52

Title: change gl*Pointer into LWJGL
Post by: rasirdas on July 24, 2006, 14:02:52
color
glColorPointer(int i, int j, int k, byte abyte0[])
glColorPointer(int i, int j, int k, short aword0[]);

normal
glNormalPointer(int i, int j, byte abyte0[])
glNormalPointer(int i, int j, short aword0[])

texcoord
glTexCoordPointer(int i, int j, int k, byte abyte0[])
glTexCoordPointer(int i, int j, int k, short aword0[])

vertex
glVertexPointer(int i, int j, int k, byte abyte0[])
glVertexPointer(int i, int j, int k, short aword0[])

please help me how to change the above methods that can run in LWJGL!!
Title: change gl*Pointer into LWJGL
Post by: Evil-Devil on July 24, 2006, 15:09:08
You have to use a NIO Buffer (int, float, depending on the method signature).

See the LWJGL documentation for more details.

http://www.lwjgl.org/javadoc/
Title: change gl*Pointer into LWJGL
Post by: rasirdas on July 24, 2006, 15:37:47
glColorPointer

public static void glColorPointer(int size,
                                 int stride,
                                 java.nio.DoubleBuffer pointer)

glColorPointer

public static void glColorPointer(int size,
                                 int stride,
                                 java.nio.FloatBuffer pointer)

but the LWJGL just support FloatBuffer or DoubleBuffer... how to deal with the byte array or short array?
Title: change gl*Pointer into LWJGL
Post by: Evil-Devil on July 24, 2006, 15:44:18

// imports...

FloatBuffer myFloatBuffer = ByteBuffer.allocateDirect(sizeOfArray).asFloatBuffer();
myFloatBuffer.put(myFloatArray);
myFloatBuffer.flip();

// data is in, use it
glColorPointer(sizeOfArray,???,myFloatBuffer);


@???: I think that the stride parameter takes care of the color. i.e. RGB (3) or RGBA (4). THe OpenGL Documentation should clarify this, I do not have a copy of it here at work ;)

//edit: Instead of creating the buffer by yourself you can use the BufferUtils class from the "org.lwjgl" packge.

//edit 2: ByteBuffers are also accepted. Only no shortbuffers. There is no need for them. Because opengl itself uses only floats.
Title: change gl*Pointer into LWJGL
Post by: darkprophet on July 24, 2006, 21:46:58
Quote

FloatBuffer myFloatBuffer = ByteBuffer.allocateDirect(sizeOfArray).asFloatBuffer();


It technically should be:


FloatBuffer myFloatBuffer = ByteBuffer.allocateDirect(sizeOfArray).order(ByteOrder.nativeOrder()).asFloatBuffer();


@Evil-Devil. the method you gave is wrong, its this:


glColorPointer(4, 0, myFloatBuffer);


The first argument is 4 if RGBA, and 3 if its RGB. 0 is how much to skip in the myFloatBuffer to obtain the next colour; useful for interleaved arrays.

DP
Title: change gl*Pointer into LWJGL
Post by: rasirdas on July 25, 2006, 01:30:14
In GL4JAVA, there has the method as following:
glColorPointer(int i, int j, int k, short aword0[]);

how can I port this method to LWJGL???
Title: change gl*Pointer into LWJGL
Post by: Evil-Devil on July 25, 2006, 07:21:30
Quote from: "darkprophet"
The first argument is 4 if RGBA, and 3 if its RGB. 0 is how much to skip in the myFloatBuffer to obtain the next colour; useful for interleaved arrays.
Ah, thats the stride for :) good to know, need to read more in the ogl bible.

@buffer: I know that it should be ordered by native order, but for the example it should still working. Or he uses the BufferUtils as mentioned.
Title: hmmmmmm....
Post by: Fool Running on July 27, 2006, 23:36:04
QuoteIn GL4JAVA, there has the method as following:
glColorPointer(int i, int j, int k, short aword0[]);

how can I port this method to LWJGL???
There is no need to port it (to my knowledge). Just use floats (If Evil-Devil is right (of course he is :lol: ), OpenGL uses floats internally anyways). I think you just divide all the shorts by 255 to get the equivalent float value.