Simple sample to show you how to write a pixel, and how to do double buffering.
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, 15, 11025,16,1,60, 1);
while(1)
{
unsigned long pad=gp2x_joystick_read();
unsigned short color;
if(pad & GP2X_VOL_DOWN) if(pad & GP2X_START) exit(0);
if(pad & GP2X_A) color=gp2x_video_RGB_color15(255,0,0,0); //red
else color=gp2x_video_RGB_color15(255,255,255,0); //white
gp2x_video_RGB[0].screen16[160+120*320]=color;
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, 15 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 gp2x_video_RGB_color15 line sets color variable to a determinated color.
- Our gp2x_video_RGB [0].screen16 line updates the pixel at the middle of screen (160,120) with our color.
- Our gp2x_video_RGB_flip line updates the screen and our gp2x_video_RGB [0].screen16 pointer for next frame.
- 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 15bits.c -static -lpthread -lm
C++ Compilation
arm-linux-g++ minimal.c 15bits.c -static -lpthread -lm
Output
- this program puts a pixel at center of screen and does double buffering (pressing A changes the color).
- press volume down and start buttons to exit.