Simple sample to show you how to use palettes.
Using library
GP2X minimal library by rlyeh, 2005
License
- Free for non-commercial projects (it would be nice receiving a mail from you). Other cases, ask me first.
- GamePark Holdings is not allowed to use this library and/or use parts from it.
Source code
#include "minimal.h"
int main(int argc, char *argv[])
{
gp2x_init(1000, 8, 11025,16,1,60, 1);
//set & update color #1 (as white)
gp2x_video_RGB_color8(255,255,255,1);
gp2x_video_RGB_setpalette();
while(1)
{
unsigned long pad=gp2x_joystick_read(), R=0,G=0,B=0;
if(pad & GP2X_VOL_DOWN) if(pad & GP2X_START) exit(0);
if(pad & GP2X_A) R=255;
if(pad & GP2X_X) G=255;
if(pad & GP2X_B) B=255;
//set & update color #0
gp2x_video_RGB_color8(R,G,B,0);
gp2x_video_RGB_setpalette();
//put a white pixel (color #1) at center of screen (160,120)
gp2x_video_RGB[0].screen8[160+120*320]=1;
gp2x_video_RGB_flip(0);
}
}
void gp2x_sound_frame(void *blah, void *buff, int samples) { }
Explanation
- Our gp2x_init line inits the whole library. We set 1000 ticks per second, 8 bits video mode, 11025/16bits/stereo/60Hz sound mode, and solid font.
- Our gp2x_joystick_read line reads the joystick. It is used to act properly to different button combinations.
- Our first gp2x_video_RGB_color8 line sets color entry 1 to white.
- Our second gp2x_video_RGB_color8 line sets color entry 0 to a determinated color. Note that the whole screen defaults to entry 0, so this will change the entire screen.
- Our gp2x_video_RGB_setpalette line updates all gp2x_video_RGB_color8 changes. So at this point exactly the screen color will change.
- Our gp2x_video_RGB [0].screen8 line will plot a white pixel (color #1) at center of screen.
- Our gp2x_sound_frame line fills our sound buffer. Note that this function will not generate any sound since we have written a void function.
C Compilation
arm-linux-gcc minimal.c 8bits.c -static -lpthread -lm
C++ Compilation
arm-linux-g++ minimal.c 8bits.c -static -lpthread -lm
Output
- this program show different color patterns when you press buttons (pressing A,X and/or B changes the color).
- press volume down and start buttons to exit.