Receiving input in pspgl

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
JustChris
Posts: 21
Joined: Thu Nov 03, 2005 7:17 am

Receiving input in pspgl

Post by JustChris »

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.
Shatterdome
Posts: 11
Joined: Tue Nov 22, 2005 6:49 pm

Post by Shatterdome »

Wel i'll give you the answer because I wish someone would have told me when I was trying to figure it out :P

Code: Select all


#include <pspctrl.h>

sceCtrlSetSamplingCycle&#40;0&#41;;
sceCtrlSetSamplingMode&#40;PSP_CTRL_MODE_ANALOG&#41;;

sceCtrlReadBufferPositive&#40;&pad, 1&#41;; 
                 
                 if &#40;pad.Buttons & PSP_CTRL_SQUARE&#41;
                     sceKernelExitGame&#40;&#41;;   
 
                 if &#40;pad.Buttons & PSP_CTRL_LEFT&#41;
                     xmod = -1;
                     

                  if &#40;pad.Buttons & PSP_CTRL_DOWN&#41;
                      ymod = 1;
                                                

                  if &#40;pad.Buttons & PSP_CTRL_RIGHT&#41;
                     xmod = 1;
                   
                               
                  if &#40;pad.Buttons & PSP_CTRL_UP&#41;
                     ymod = -1

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
JustChris
Posts: 21
Joined: Thu Nov 03, 2005 7:17 am

Post by JustChris »

I already know how to do this with pspctrl.h, but here I'm just looking for the glut way. Meanwhile, I'll just try to combine that functionality with glut and see what happens, if using two different input methods conflict at all.
JustChris
Posts: 21
Joined: Thu Nov 03, 2005 7:17 am

Post by JustChris »

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

Code: Select all

#define RUMBLE	&#40;1<<0&#41;
#define ROCKING	&#40;1<<1&#41;
#define ZOOM	&#40;1<<2&#41;
#define PAUSE	&#40;1<<3&#41;
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.

Code: Select all

static void keydown &#40;unsigned char key, int x, int y&#41;
&#123;
	press = 0;

	switch &#40;key&#41; &#123;
	case 'd'&#58;			/* delta, triangle */
		press |= ROCKING;
		break;
	case 'o'&#58;			/* round */
		press |= PAUSE;
		break;
	case 'q'&#58;			/* square*/
		press |= RUMBLE;
		break;
	case 'x'&#58;			/* cross button */
		press |= ZOOM;
		break;
	default&#58;
		;
	&#125;
&#125;
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]
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Post by jsgf »

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:

Code: Select all

void specialkey&#40;int key, int x, int y&#41;
&#123;
    switch&#40;key&#41; &#123;
    case GLUT_KEY_UP&#58; ...
    case GLUT_KEY_DOWN&#58;....
   &#125;
&#125;

//...
    glutSpecialFunc&#40;specialkey&#41;;
    glutSpecialUpFunc&#40;specialkeyup&#41;;
Look at glut.c in PSPGL to see how this is implemented.
JustChris
Posts: 21
Joined: Thu Nov 03, 2005 7:17 am

Post by JustChris »

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.
Post Reply