473,770 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(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);
Jul 17 '05 #1
1 5036
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(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);


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
1858
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
4543
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
3219
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. -- Myk Quayce "If we can't be free, at least we can be cheap." - Frank Zappa
3
9991
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 OpenGL.GLUT import *
3
1390
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 loaded, but not how to get the textures from VB into the shader. If i set up two samplers in the shader with no associated texture then when I compile the shader from string works fine. but when the shader actually runs both sample the same texture...
2
1677
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 Texture { public: // openGl data here glInt GetInt();
0
1467
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 import *
7
2107
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 the debugger even in release mode it takes a second or so to load a 65k texture, with a 2ghz pc this is 10k instructions per pixel ! I cant understand what its doing here, can anyone shed any light on this ? I have the d3d debug turned off...
0
1561
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; BYTE * data; FILE * file;
0
9617
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10037
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9904
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.