Jump to content
  • Advertisement
Sign in to follow this  
marklit

OpenGL Creating a Texture in PHP and OpenGL

This topic is 5012 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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);

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Cheers for the reply. I did that and it came back completely red, that was using:

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

Any ideas?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!