Dynamic array and OpenGL problem

Johan Granberg lijat.meREM at OVEgmail.com
Sun Jan 13 14:27:30 PST 2008


Mikko Ronkainen wrote:

> Hello, Iäm playing around a little with OpenGL and I'm drawing trying to
> draw raw pixels from memory to the screen. This is the function:
> 
> void glDrawPixels(GLsizei width, GLsizei height, GLenum format, GLenum
> type, const GLvoid *pixels);
> 
> Now I have a buffer with rgb data:
> 
> ubyte[3][1024][1280] framebuffer;

This creates a static array that is consecutive in memmory 

> If I fill it and pass it to the opengl, everything works fine. But if I
> create it dynamically:
> 
> ubyte[][][] framebuffer;
> framebuffer = new ubyte[][][](3, height, width);

This creates a dynamic array (of a dynamic arrays), dynamic arrays wont be
consecutive in memory in the same way.

A dynamic array is a pair of a size and a pointer so if you pass that to
opengl which expects the array to be consecutive in memmory opengl will
read the length part of the array as if it was part of the data and therfor
producing garbage

> Now even after filling it I get some random garbage when rendering.
> Program doesn't segfault though, so I assume memory is correctly allocated
> and written - opengl just doesn't read it right. What am I doing wrong?



More information about the Digitalmars-d-learn mailing list