By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,437 Members | 1,660 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,437 IT Pros & Developers. It's quick & easy.

Creating a texture in PHP + OpenGL

P: n/a
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_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);

glTexImage2D(GL_TEXTURE_2D, 0, 3,
256, 256,
0, GL_RGB, GL_UNSIGNED_BYTE, $p);
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Mark L wrote:
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.
I cant really figure it out, seems to me that it has something to do
with a difference in php's internal representation of arrays/scalar
values and the way glTexImage2D works. I have tried different
combinations but only the tweaks below worked for me.

If you got the source code for glTexImage2D, it might reveal somehting.

$p = "";
not vital but
$p = range(0, $width*$height*$depth);
would be more correct as an initialization
$pos = 0;

for( $x = 0; $x < 256; $x ++ )
for( $y = 0; $y < 256; $y ++ )
for( $d = 0; $d < 4; $d ++ )
{
switch ($d) { //color layer
case 0://red 0xR------- //Only the highorder nibble had any effect.
$p[$pos] = 0x50000000;
break;
case 1://green 0xG-------
$p[$pos] = 0x70000000;
break;
case 2://blue 0xB-------
$p[$pos] = 0xa0000000;
break;
case 3://alpha? does not seem to have any effect
$p[$pos] = 0x00000000;
break;
}
$pos ++;

}

glGenTextures(1, &$textpoint );
glBindTexture(GL_TEXTURE_2D, $textpoint[ 0 ] );
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);

glTexImage2D(GL_TEXTURE_2D, 0, 3,
256, 256,
0, GL_RGB, GL_UNSIGNED_BYTE, $p);


glTexImage2D(GL_TEXTURE_2D, 0, 3,
256, 256,
0, GL_RGBA, GL_UNSIGNED_INT, $p);

Changed to match the structure of "$p"
/Bent
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.