473,322 Members | 1,911 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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:
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
1 4996
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: skarr | last post by:
Heya, I have a text file which is basically an array declaration and I would like to assign this to a array variable. It reads like this (extract) myProfile = { = { = {
15
by: oracle411 | last post by:
Hi I'm new to OpenGL, but have an OpenGL application written in CPP that I would like to display on a web browser. Was wondering how this could be done? Thank you very much
1
by: Myk Quayce | last post by:
I have a four-sided polygon that rotates and zooms as the user moves the mouse. Is there a way to incorporate a texture-mapped image without DirectX? The GDI+ doesn't seem to support this. -- ...
3
by: jg.campbell.ng | last post by:
I'm beginning learning Python and OpenGL in Python. Python fine. But difficulties with OpenGL; presumably with the installation of OpenGL. OS = Linux FC5. Python program gl_test.py: from...
3
by: x | last post by:
Still fairly new at this, I have been trying to find out how to compile and effect with multiple samplers. Been able to find loads of examples that show the HSL code once the samplers are...
2
by: =?ISO-8859-2?Q?Rafa=B3?= Maj | last post by:
Say we have a class Model (a 3d model) and class Texture (representing an Texture). Model have a texture, Model can be Drawed. Texture have method that returns data needed for drawing. class...
0
by: ...:::JA:::... | last post by:
Hello, Is there any real easy example for loading an texture in your directpython window??? For example this is my code: # loading directpython modules import d3dx import d3d from d3dc...
7
by: colin | last post by:
Hi, Ive written a 3dmodel editor, and it works fairly well it harldy uses any cpu exept when its loading a texture from bitmap in the debugger, at all other times it hardly uses any cpu but from...
0
by: brixton | last post by:
Hello, I've got the following code that creates a texture from a .RAW file: GLuint MyGLCanvas::LoadTextureRAW( const char * filename, int wrap ) { GLuint texture; int width, height; ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.