PDK OpenGL ES Tutorial 1

From WebOS101

Jump to: navigation, search

Welcome. I am working on this tutorial right as you view it. It should be done soon. If you encounter problems while going through these tutorials, feel free to come into #webOS on irc.freenode.net and ask questions. Or the palm developer forums are a good place to ask questions.

PDK Versus SDK

If you're wondering to yourself whether or not you need the PDK, I'll try to simplify it for you. For most simple 2D games, you can get everything you need from javascript/html/css. If you require responsive sounds (as close to instantaneous as possible), a physics engine, lots of high quality textures, 3D, a ton of drawing logic, or multitouch interaction, you definitely need to use the PDK.

Setup & Structure of the PDK

Setting up the PDK is very simple. Download the latest webOS SDK (which includes the PDK) and run the installer.

The PDK/SDK (as of 1.4.5) installs to /opt/PalmPDK & /opt/PalmSDK on Mac OS X and (directory needed) on Windows. From now on, regardless of platform, the /PalmPDK/ refers to the Palm PDK directory for your specific operating system. Ultimately the developer environment you use shouldn't matter as all the libraries are included for you. Inside of the /PalmPDK/ directory are the following:

/PalmPDK/
->/arm/ - Contains compilers for the device
->/bin/ - A few developer tools, we'll get to them as we need them
->/device/ - Contains all the libraries that are included on the device
->/host/ - libraries for your computer
->/include/ - header files for the libraries
->/share/ - Some sample code for developers to look at

If you're looking for sample code, and want to skip tutorials, you can check in /PalmPDK/share/samplecode/simple for an application that is ready for the device.

The PDK uses SDL as an abstraction layer to the hardware. What this means, is that if you want to access hardware features, you need to use SDL. We'll go over this more in a bit.

A Code Walk-Through

In this code I've removed all the parts that would do anything, and stripped it to the basics. We're going to start building the program up from here.

//The Base code for an PDK game, only 2 libraries needed  
#include "SDL.h"
#include "PDL.h"
 
SDL_Surface *Surface; // Screen surface to retrieve width/height information
 
 
int main(int argc, char** argv)
{
// Initialize the SDL library with the Video subsystem
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
 
// start the PDL library
PDL_Init(0);
 
// Set the video mode to full screen SDL_VIDEO
Surface = SDL_SetVideoMode(320, 480, 0, SDL_VIDEO);
 
// Application specific Initialize of data structures & GL states
if (Init() == false)
return -1;
 
// Event descriptor
SDL_Event Event;
 
//The following while loop is where everything will eventually happen, if the escape key is pressed, it returns 1 and then breaks
while (1){
 
 
while (SDL_PollEvent(&Event)) {
switch (Event.type) {
// List of keys that have been pressed
case SDL_KEYDOWN:
break;
//listen for key events
case SDL_KEYUP:
// If escape is pressed return and quit the app
if (event.key.keysym.sym == SDLK_ESCAPE)
return 0;
break;
 
}
break;
}
}
 
}
 
// Cleanup
PDL_Quit();
SDL_Quit();
 
return 0;
}

There's not much to understand here. The program will initialize data until it reaches the while(1) loop. This is where the program should preform repetitive tasks like rendering frames, updating states, etc. In addition to those libraries, you have all the standard libraries available to use. We're going to jump right into OpenGL ES 1.1 in Tutorial 2.

Personal tools