dumbass
01-05-2012, 09:10 AM
Hi all, Im using PHP in XAMPP with SDL. I'm trying to run this piece of code but keep getting these 2 errors.
Warning: register_shutdown_function() [function.register-shutdown-function]: Invalid shutdown callback 'phpSDL_Quit' passed in C:\xampp\htdocs\sdlfirst.php on line 11
Fatal error: Call to undefined function phpsdl_init() in C:\xampp\htdocs\sdlfirst.php on line 14
My code is as follows:
<?php
#let it run forever
set_time_limit(0);
#tells SDL library to close everything and unload itself
register_shutdown_function("phpSDL_Quit");
#tells SDL to start up and initialise its video library, returns an error if it doesnt start properly
if (phpSDL_Init(SDL_INIT_VIDEO) < 0) exit;
#creates main window - width, height, bits per pixel, flags
$video = phpSDL_SetVideoMode(1000, 800, 0, SDL_HWSURFACE | SDL_DOUBLEBUF);
if(!$video) exit;
#ignore all events except a key being pressed or clicking exit button
for ( $i = 0; $i<SDL_NUMEVENTS; ++$i ) {
if ( ($i != SDL_KEYDOWN) && ($i != SDL_QUIT) ) {
phpSDL_EventState($i, SDL_IGNORE);
}
}
#loads windows bitmap file
$bmp = phpSDL_LoadBMP("mypic.bmp");
$dest['x'] = 0;
$dest['y'] = 10;
$dest['w'] = 0;
$dest['h'] = 0;
#define the colour black to clear the screen
$blue = phpSDL_MapRGB($video['format'], 28, 65, 112);
#decide whether to exit the main loop
$done = false;
$screensize = array("x"=>0,"y"=>0,"w"=>1000,"h"=>800);
while(!$done) {
#fill the whole screen with black
phpSDL_FillRect($video, $screensize, $blue);
$event = array();
while (phpSDL_PollEvent(&$event)) {
switch($event['type']) {
case SDL_QUIT:
$done = true;
break;
case SDL_KEYDOWN:
if ($event['key']['keysym']['sym'] == SDLK_ESCAPE) {
$done = 1;
}
break;
}
}
$keys = phpSDL_GetKeyState(&$numkeys);
if ( $keys[SDLK_UP] ) { --$dest['y']; }
if ( $keys[SDLK_DOWN] ) { ++$dest['y']; }
if ($keys[SDLK_UP] && $dest['y'] <= 10){
$dest['y'] = 10;
}
if ($keys[SDLK_DOWN] && $dest['y'] >=700){
$dest['y'] = 700;
}
#if ( $keys[SDLK_LEFT] ) { --$dest['x']; }
#if ( $keys[SDLK_RIGHT] ) { ++$dest['x']; }
#draws bitmap surface on back buffer
phpSDL_BlitSurface($bmp, NULL, $video, $dest);
#the back buffer becomes the front buffer (visible) and the old front buffer becomes the new back buffer
phpSDL_flip($video);
}
#frees up memory allocated to the bitmap
phpSDL_FreeSurface($bmp);
#set caption
phpSDL_WM_SetCaption("Nyan Cat: Lost in Cyber Space", "Nyan Cat: Lost in Cyber Space");
?>
Please help :confused:
Warning: register_shutdown_function() [function.register-shutdown-function]: Invalid shutdown callback 'phpSDL_Quit' passed in C:\xampp\htdocs\sdlfirst.php on line 11
Fatal error: Call to undefined function phpsdl_init() in C:\xampp\htdocs\sdlfirst.php on line 14
My code is as follows:
<?php
#let it run forever
set_time_limit(0);
#tells SDL library to close everything and unload itself
register_shutdown_function("phpSDL_Quit");
#tells SDL to start up and initialise its video library, returns an error if it doesnt start properly
if (phpSDL_Init(SDL_INIT_VIDEO) < 0) exit;
#creates main window - width, height, bits per pixel, flags
$video = phpSDL_SetVideoMode(1000, 800, 0, SDL_HWSURFACE | SDL_DOUBLEBUF);
if(!$video) exit;
#ignore all events except a key being pressed or clicking exit button
for ( $i = 0; $i<SDL_NUMEVENTS; ++$i ) {
if ( ($i != SDL_KEYDOWN) && ($i != SDL_QUIT) ) {
phpSDL_EventState($i, SDL_IGNORE);
}
}
#loads windows bitmap file
$bmp = phpSDL_LoadBMP("mypic.bmp");
$dest['x'] = 0;
$dest['y'] = 10;
$dest['w'] = 0;
$dest['h'] = 0;
#define the colour black to clear the screen
$blue = phpSDL_MapRGB($video['format'], 28, 65, 112);
#decide whether to exit the main loop
$done = false;
$screensize = array("x"=>0,"y"=>0,"w"=>1000,"h"=>800);
while(!$done) {
#fill the whole screen with black
phpSDL_FillRect($video, $screensize, $blue);
$event = array();
while (phpSDL_PollEvent(&$event)) {
switch($event['type']) {
case SDL_QUIT:
$done = true;
break;
case SDL_KEYDOWN:
if ($event['key']['keysym']['sym'] == SDLK_ESCAPE) {
$done = 1;
}
break;
}
}
$keys = phpSDL_GetKeyState(&$numkeys);
if ( $keys[SDLK_UP] ) { --$dest['y']; }
if ( $keys[SDLK_DOWN] ) { ++$dest['y']; }
if ($keys[SDLK_UP] && $dest['y'] <= 10){
$dest['y'] = 10;
}
if ($keys[SDLK_DOWN] && $dest['y'] >=700){
$dest['y'] = 700;
}
#if ( $keys[SDLK_LEFT] ) { --$dest['x']; }
#if ( $keys[SDLK_RIGHT] ) { ++$dest['x']; }
#draws bitmap surface on back buffer
phpSDL_BlitSurface($bmp, NULL, $video, $dest);
#the back buffer becomes the front buffer (visible) and the old front buffer becomes the new back buffer
phpSDL_flip($video);
}
#frees up memory allocated to the bitmap
phpSDL_FreeSurface($bmp);
#set caption
phpSDL_WM_SetCaption("Nyan Cat: Lost in Cyber Space", "Nyan Cat: Lost in Cyber Space");
?>
Please help :confused: