main.cpp
#include <stdio.h>
#include <stdlib.h>
#include <SDL.h>
int main(int argc, char** args)
{
SDL_Rect of;
SDL_Surface *bg = NULL;
SDL_Surface *msg = NULL;
SDL_Surface *screen = NULL;
SDL_Surface *loadedImage = NULL;
if (SDL_Init(SDL_INIT_EVERYTHING) == -1) {
printf("failed to SDL_Init\n");
return -1;
}
screen = SDL_SetVideoMode(1440, 1440, 32, SDL_SWSURFACE);
if (screen == NULL) {
printf("failed to SD_SetVideMode\n");
return -1;
}
SDL_ShowCursor(0);
loadedImage = SDL_LoadBMP("app/native/bg.bmp");
if (loadedImage != NULL) {
bg = SDL_DisplayFormat(loadedImage);
SDL_FreeSurface(loadedImage);
}
loadedImage = SDL_LoadBMP("app/native/msg.bmp");
if (loadedImage != NULL) {
msg = SDL_DisplayFormat(loadedImage);
SDL_FreeSurface(loadedImage);
}
of.x = 0;
of.y= 0;
SDL_BlitSurface(bg, NULL, screen, &of);
of.x = 320;
of.y= 0;
SDL_BlitSurface(bg, NULL, screen, &of);
of.x = 0;
of.y= 240;
SDL_BlitSurface(bg, NULL, screen, &of);
of.x = 320;
of.y= 240;
SDL_BlitSurface(bg, NULL, screen, &of);
of.x = 80;
of.y= 60;
SDL_BlitSurface(msg, NULL, screen, &of);
SDL_Flip(screen);
SDL_Delay(30000);
SDL_FreeSurface(bg);
SDL_FreeSurface(msg);
SDL_Quit();
return 0;
}
bar-descriptor.xml
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<qnx xmlns="http://www.qnx.com/schemas/application/1.0">
<id>com.steward.sdl.ch2</id>
<name>ch2</name>
<filename>ch2</filename>
<versionNumber>1.0.0</versionNumber>
<buildId>1</buildId>
<description>Lesson 2. Optimized Surface Loading and Blitting</description>
<author>Steward</author>
<authorId>gYAAgGE4qaHzBnzEAu8JKe4G1OI</authorId>
<asset path="main" entry="true" type="Qnx/Elf">main</asset>
<asset path="bg.bmp">bg.bmp</asset>
<asset path="msg.bmp">msg.bmp</asset>
<asset path="lib" type="Qnx/Elf">lib</asset>
<permission system="true">run_native</permission>
<env var="LD_LIBRARY_PATH" value="app/native/lib"/>
</qnx>
Makefile
main: main.cpp
ntoarmv7-gcc main.cpp -g -o main lib/libSDL-1.2.so.11 -Iinclude
blackberry-nativepackager -package main.bar bar-descriptor.xml -devMode -debugToken ${HOME}/.rim/debugtoken_q30.bar
clean:
rm -rf main
rm -rf main.bar
完成

