Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-05-2012, 09:10 AM   PM User | #1
dumbass
New to the CF scene

 
Join Date: Jan 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
dumbass is an unknown quantity at this point
PHP with SDL in XAMPP

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:

Code:
    <?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
dumbass is offline   Reply With Quote
Reply

Bookmarks

Tags
graphics, php, sdl, xampp

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:13 PM.


Advertisement
Log in to turn off these ads.