change gl*Pointer into LWJGL

Started by rasirdas, July 24, 2006, 14:02:52

Previous topic - Next topic

rasirdas

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!!

Evil-Devil

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/

rasirdas

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?

Evil-Devil

// 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.

darkprophet

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

rasirdas

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???

Evil-Devil

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.

Fool Running

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.
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D