[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: [LUAJit] ffi and pointer math
- From: Kaj Eijlers <bizziboi@...>
- Date: Tue, 10 May 2011 20:04:43 -0700
Hi,
God I love LuaJit. Sliced bread can finally retire.
However.....
I am trying to do some openGL, which works like a charm, but I've ran into a problem. I'm sure it's me but I can't figure it out.
I need to pass in a pointer to an array of structs, which poses no problem,
typedef struct
{
float u;
float v;
} TexCoords;
typedef struct
{
float x;
float y;
} Positions;
typedef unsigned int Colors;
typedef struct
{
Positions Position;
TexCoords TexCoord;
Colors Color;
} PTC;
Creating an array of those with
local verts = ffi.new("PTC[3]")
local vertOffs = verts
sending the pointer off:
gl.glVertexPointer(2, gl.GL_FLOAT, ffi.sizeof("PTC"), vertoffs);
Works like a charm, the sizeof is the stride, vertoffs the pointer (although I am not sure if I created a copy when I assigned to 'verts')
Now I need to pass a pointer to a member inside PTC, in this case TexCoords which would be at offset 8.
Try as I might I can't create a pointer to it.
I tried
local tex = verts + 8 but that doesn't work
I tried
local ptr = ffi.new("unsigned char*")
ptr = verts
ptr = ptr + 8
But it doesn't do what I expect.
So my question...if I have a pointer to data (as verts is if I understand correctly), how do I add a value to the pointer?
Any pointers (har har) appreciated.
Kaj