Code: Select all
#include <pspkernel.h>
#include <pspthreadman.h>
#include <pspiofilemgr.h>
#include <pspiofilemgr_dirent.h>
#include <pspctrl.h>
#include <pspdisplay.h>
#include <pspdebug.h>
#include <psprtc.h>
#include <GLES/egl.h>
#include <GL/gl.h>
#include <stdlib.h>
#include <string.h>
/* Define the module info section */
PSP_MODULE_INFO("test", 0, 1, 1);
/* Define the main thread's attribute value (optional) */
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
static int done = 0;
/* Exit callback */
int exit_callback(void)
{
done = 1;
return 0;
}
/* Callback thread */
void CallbackThread(void *arg)
{
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", (void *)exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void)
{
int thid = 0;
thid = sceKernelCreateThread("update_thread", (void *)CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0)
{
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
static const EGLint attrib_list[]=
{
EGL_RED_SIZE, 1,
EGL_GREEN_SIZE, 1,
EGL_BLUE_SIZE, 1,
EGL_ALPHA_SIZE, 0,
EGL_DEPTH_SIZE, 0,
EGL_NONE
};
EGLDisplay dpy;
EGLSurface surface;
static void init_egl(void)
{
EGLConfig config;
EGLint num_configs;
EGLContext ctx;
dpy = eglGetDisplay(0);
eglInitialize(dpy, NULL, NULL);
eglChooseConfig(dpy, attrib_list, &config, 1, &num_configs);
if (num_configs == 0)
return;
ctx = eglCreateContext(dpy, config, NULL, NULL);
surface = eglCreateWindowSurface(dpy, config, 0, NULL);
eglMakeCurrent(dpy, surface, surface, ctx);
}
int main(int argc, char **argv)
{
SceCtrlData pad;
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
init_egl();
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Black Background
glDepthFunc(GL_ALWAYS);
glDisable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT);
//viewport in top left hand corner of window
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(0,640,480,0,-1,1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDrawBuffer(GL_BACK);
glViewport(0,0,(GLsizei)480,(GLsizei)272);
SetupCallbacks();
glColor3ub(255,255,255);
do
{
glBegin(GL_QUADS);
glVertex2i(0,0);
glVertex2i(100,0);
glVertex2i(100,100);
glVertex2i(0,100);
glVertex2i(150+0,0);
glVertex2i(150+100,0);
glVertex2i(150+100,100);
glVertex2i(150+0,100);
glEnd();
glBegin(GL_QUADS);
glVertex2i(0,150+0);
glVertex2i(100,150+0);
glVertex2i(100,150+100);
glVertex2i(0,150+100);
glEnd();
glBegin(GL_QUADS);
glVertex2i(150+0,150+0);
glVertex2i(150+100,150+0);
glVertex2i(150+100,150+100);
glVertex2i(150+0,150+100);
glEnd();
eglSwapBuffers(dpy, surface);
sceCtrlReadBufferPositive(&pad, 1);
} while (!pad.Buttons && !done);
sceKernelExitGame();
return 0;
}
I'm using today's SVN pspgl.
Thanks in advance for any insight.
Jim