Creating a Texture in PHP and OpenGL
I am trying to create a graphics engine using OpenGL and PHP. I am currently trying to create a completly white texture to test out the texturing capabilities.
My idea is to create an array 256x256x3 of the value 255 to create a completely white texture. When I do this in C it works fine but in PHP I get a array of red, blue, green and black lines texturing the cube.
I have built a webpage detailing this problem:
http://www.marksblogg.com/opengl-php-texturing/
The texture creation happens in the following code. I appolgies that I didn't clean up the code more prior to this. Any help or ideas would be greatly appriciated.
$textpoint = null;
$p = "";
$pos = 0;
for( $x = 0; $x < 256; $x ++ )
for( $y = 0; $y < 256; $y ++ )
for( $d = 0; $d < 4; $d ++ )
{
// comes up black:
//$p[ $pos ] = sprintf( "%c", 255 );
// comes up with Red, green, blue, black stripes
//$p[ $pos ] = 0xff;
// comes up with Red, green, blue, black stripes
$p[ $pos ] = 255;
$pos ++;
}
glGenTextures(1, &$textpoint );
glBindTexture(GL_TEXTURE_2D, $textpoint[ 0 ] );
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3,
256, 256,
0, GL_RGB, GL_UNSIGNED_BYTE, $p);
Quote:
for( $x = 0; $x < 256; $x ++ )
for( $y = 0; $y < 256; $y ++ )
for( $d = 0; $d < 4; $d ++ )
Isn't this 256x256x4? Either change GL_RGB to GL_RGBA or build an 256x256x3 array.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement