I have played around with the pspgl sprite demo long enough to finally be able to port my game logic from a shooter I made in SDL (on PC) over to the PSP. I'm stuck on how pspgl receives all the key inputs, though.
Using glutJoystickFunc is straightforward, but the sprite demo only shows the letters assigned to the Square, Triangle, Cross and Circle buttons. I really want to get input with the directional buttons rather than the analog nub. So which letters on the keyboard correspond the D-pad directions, as well as Select and Start? I could not find the assignment to these particular buttons in GL/glut.h.
Receiving input in pspgl
-
- Posts: 11
- Joined: Tue Nov 22, 2005 6:49 pm
Wel i'll give you the answer because I wish someone would have told me when I was trying to figure it out :P
It's not using glut.h, but I don't see why you couldn't use it, it's pretty straight forward....just replace UP or RIGHT etc with TRIANGLE or SELECT or START...I THINK triggers are LTRIGGER RTRIGGER...
Prolly a better way to do it, but this works for me :P
Code: Select all
#include <pspctrl.h>
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
sceCtrlReadBufferPositive(&pad, 1);
if (pad.Buttons & PSP_CTRL_SQUARE)
sceKernelExitGame();
if (pad.Buttons & PSP_CTRL_LEFT)
xmod = -1;
if (pad.Buttons & PSP_CTRL_DOWN)
ymod = 1;
if (pad.Buttons & PSP_CTRL_RIGHT)
xmod = 1;
if (pad.Buttons & PSP_CTRL_UP)
ymod = -1
Prolly a better way to do it, but this works for me :P
Let me see it anyone can answer this question. In the pspgl sprite demo (the one with the sky background and 4 rows of icons that you can shake and rotate) there is a list of keys assigned to 4 buttons on the PSP.
Near the beginning of the file I find the four actions defined here
And further down is the keydown function which gets initialized in the main loop. The comments were already in the file when I opened it.
How were the letters chosen assigned to the buttons on the PSP and how can I, for example, figure out the letters that correspond to the other buttons? The demo only used these buttons plus the analog nub. Plus, do the numbers defined in the four actions have any significance?[/code]
Near the beginning of the file I find the four actions defined here
Code: Select all
#define RUMBLE (1<<0)
#define ROCKING (1<<1)
#define ZOOM (1<<2)
#define PAUSE (1<<3)
Code: Select all
static void keydown (unsigned char key, int x, int y)
{
press = 0;
switch (key) {
case 'd': /* delta, triangle */
press |= ROCKING;
break;
case 'o': /* round */
press |= PAUSE;
break;
case 'q': /* square*/
press |= RUMBLE;
break;
case 'x': /* cross button */
press |= ZOOM;
break;
default:
;
}
}
Note that glut is a standard API, and not psp-specific, so you can look for documentation elsewhere. But like the rest of PSPGL, it isn't complete compared to real glut, but it's worth trying anyway.
The letters are somewhat arbitrary but are intended to be mnemonic: 'o' looks like a circle, 'd' for a triangle-shaped delta, 'q' for sQuare, 's' for select, 'a' for stArt, 'x' for cross, etc.
The arrow keys come through the Special callback, so you need something like:
Look at glut.c in PSPGL to see how this is implemented.
The letters are somewhat arbitrary but are intended to be mnemonic: 'o' looks like a circle, 'd' for a triangle-shaped delta, 'q' for sQuare, 's' for select, 'a' for stArt, 'x' for cross, etc.
The arrow keys come through the Special callback, so you need something like:
Code: Select all
void specialkey(int key, int x, int y)
{
switch(key) {
case GLUT_KEY_UP: ...
case GLUT_KEY_DOWN:....
}
}
//...
glutSpecialFunc(specialkey);
glutSpecialUpFunc(specialkeyup);
I know that Glut is not PSP-specific, but I was just thinking that the code for the controls was initialized somewhere else. But now it makes sense to me, now that I know where to look and saw how it was done. And I can see it all boils down to using pspctrl.h and sceCtrlReadBufferPositive in the glutMainLoop function. Pretty clever.