www.xbdev.net xbdev - software development
Friday December 14, 2018
home | about | contact | Donations

     
 

OpenXDK

The Free, Legal, Open Source XBox Development Kit...

 

Simple Ouput - Basic Graphics

 

Its sometimes necessary to have something on the screen...how do we even know that our xbe is running?  Well you can plot pixels or do some graphics on the screen with a relative few lines of code!  For those who have ever programmed in DOS...programming in the openxdk will make you feel right at home..hehe

 

Download Project Code - Graphics
 

// This demo code is referenced from one of the openxdk samples on

// sourceforge - caustik

 

#include <openxdk.h>

 

#include <xgfx2d/bitmap.h>             // Bitmap*, get_screen_bitmap()..

 

// Program Entry Point

void XBoxStartup()

{

      vga_init_mode(MODE_320x240x32);    // Init screen render surface

 

      Bitmap      *screen = get_screen_bitmap();

      int xx, y, x;

      while(true)

      {

            vga_vsync();                              // Wait for Vertical Blank

            vga_flip();                               // Flip

 

            //generate a pretty colour background on the screen

            uint32      *p = screen->data;

            for (y=0; y<screen->h; y++)

            {

                  for (x=0; x<screen->w; x++)

                  {

                        *p++ = ((x+xx)^y)&0xFF;       //yay a XOR pattern!!! :D

                  }

            }

            xx++;

 

      }

    HalReturnToFirmware(ReturnFirmwareFatal);

    return;

}// End

 

 

The thing to look at in that code, is that we can access the points on the screen....I should really call them pixels :)  Each pixel is a 32 bit value...we get the screen and start putting pixels on it :)

 

Well I thought I'd do a small example that will plot directly to the Screen Surface!  Its not really what you do...but it can be used at certain times for testing.  As its not using any sync or timing...just plotting directly to the screen output.

Notice how I've commented out the '//#include <openxdk.h>' header file...as we don't need it!  Just to show you that you can do xbox programming even without external library's.

 

Download Project Code - Circle
 

//#include <openxdk.h>

 

// Small algorithm that draws simple circles

void xbvDrawCircle( unsigned int *pdwFramebuffer, int nSizeStrideInDwords,

                            unsigned int dwPixel, int xC, int yC, int r )

{

      int x=0, y=r, u=1, v=2*r-1, e=0;

 

      while( x < y ){

 

            pdwFramebuffer[(xC+x)+((yC+y)* nSizeStrideInDwords)]=dwPixel;

            pdwFramebuffer[(xC+y)+((yC-x)* nSizeStrideInDwords)]=dwPixel;

            pdwFramebuffer[(xC-x)+((yC-y)* nSizeStrideInDwords)]=dwPixel;

            pdwFramebuffer[(xC-y)+((yC+x)* nSizeStrideInDwords)]=dwPixel;

            x++; e += u; u+= 2;

            if( v < 2 * e ) { y--; e -= v; v -= 2; }

            if( x > y ) break;

            pdwFramebuffer[(xC+y)+((yC+x)* nSizeStrideInDwords)]=dwPixel;

            pdwFramebuffer[(xC+x)+((yC-y)* nSizeStrideInDwords)]=dwPixel;

            pdwFramebuffer[(xC-y)+((yC-x)* nSizeStrideInDwords)]=dwPixel;

            pdwFramebuffer[(xC-x)+((yC+y)* nSizeStrideInDwords)]=dwPixel;

      }

 

}// end of xbvDrawCircle(..)

 

// Program Entry Point

void XBoxStartup()

{

      while(true)

      {

            // Screen Memory

            unsigned int* pScr = (unsigned int*)(0xF0000000 + *(unsigned int*)0xFD600800);

            // Display an output to show we caught the error

            xbvDrawCircle( pScr, 640, 0xffffff00, 640/2, 480/2, 10 );

            xbvDrawCircle( pScr, 640, 0xffffff00, 640/2, 480/2, 50 );

            xbvDrawCircle( pScr, 640, 0xffffff00, 640/2, 480/2, 100 );

      }// End while loop

}// End

 

 

You can also use the 'xbvDrawCircle(..)' algorithm in other demo's...but with our openxdk timing...as we dont' want to see the screen getting drawn and we want to see crisp images appearing with a flash.

 

So lets do another sample program...as I say the more demos and more code you write, the better you get:

 

Download Project Code - More Pixel Plotting
 

#include <openxdk.h>    // vga_vsync()

 

// Program Entry Point

VOID XBoxStartup()

{

    uint32 *pix = (uint32*)0xF0040240;

 

    for(uint32 y=0;y<480;y++)

        for(uint32 x=0;x<640;x++)

            pix[640*y+x] = x;

 

    for(int v=0;v<60*5;v++)

        vga_vsync();

 

    return;

}// End

 

 

 

 

 

 

 

 

 

 

 
 Visitor: 9534626  { 209.237.238.175 } Copyright (c) 2002-2017 xbdev.net - All rights reserved.
Designated tutorial and software are the property of their respective owners.