Creating a texture in PHP + OpenGL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark L

    Creating a texture in PHP + 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:
    Benchmarks & Tips for Big Data, Hadoop, AWS, Google Cloud, PostgreSQL, Spark, Python & More...


    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(G L_TEXTURE_2D, $textpoint[ 0 ] );
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_ FILTER,GL_LINEA R);
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_ FILTER,GL_LINEA R);

    glTexImage2D(GL _TEXTURE_2D, 0, 3,
    256, 256,
    0, GL_RGB, GL_UNSIGNED_BYT E, $p);
  • Bent Stigsen

    #2
    Re: Creating a texture in PHP + OpenGL

    Mark L wrote:[color=blue]
    > 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.[/color]

    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.

    [color=blue]
    > $p = "";[/color]

    not vital but
    $p = range(0, $width*$height* $depth);
    would be more correct as an initialization
    [color=blue]
    > $pos = 0;
    >
    > for( $x = 0; $x < 256; $x ++ )
    > for( $y = 0; $y < 256; $y ++ )
    > for( $d = 0; $d < 4; $d ++ )
    > {[/color]

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

    [color=blue]
    > }
    >
    > glGenTextures(1 , &$textpoint );
    > glBindTexture(G L_TEXTURE_2D, $textpoint[ 0 ] );
    > glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_ FILTER,GL_LINEA R);
    > glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_ FILTER,GL_LINEA R);
    >
    > glTexImage2D(GL _TEXTURE_2D, 0, 3,
    > 256, 256,
    > 0, GL_RGB, GL_UNSIGNED_BYT E, $p);[/color]

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

    Changed to match the structure of "$p"


    /Bent

    Comment

    Working...