2021-04-30 19:47:33 +00:00
|
|
|
/*
|
|
|
|
KallistiOS 2.0.0
|
|
|
|
|
|
|
|
nehe08.c
|
|
|
|
(c)2021 Luke Benstead
|
|
|
|
(c)2014 Josh Pearson
|
|
|
|
(c)2001 Benoit Miller
|
|
|
|
(c)2000 Jeff Molofee
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef __DREAMCAST__
|
|
|
|
#include <kos.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <GL/gl.h>
|
|
|
|
#include <GL/glu.h>
|
|
|
|
#include <GL/glkos.h>
|
|
|
|
|
|
|
|
/* Simple OpenGL example to demonstrate blending and lighting.
|
|
|
|
|
|
|
|
Essentially the same thing as NeHe's lesson08 code.
|
|
|
|
To learn more, go to http://nehe.gamedev.net/.
|
|
|
|
|
|
|
|
DPAD controls the cube rotation, button A & B control the depth
|
|
|
|
of the cube, button X toggles filtering, and button Y toggles alpha
|
|
|
|
blending.
|
|
|
|
*/
|
|
|
|
|
2022-01-25 14:41:55 +00:00
|
|
|
#ifdef __DREAMCAST__
|
|
|
|
extern uint8 romdisk[];
|
|
|
|
KOS_INIT_ROMDISK(romdisk);
|
2022-01-31 16:59:05 +00:00
|
|
|
#define IMG_PATH "/rd/glass.pvr"
|
|
|
|
#else
|
|
|
|
#define IMG_PATH "../samples/nehe08/romdisk/glass.pvr"
|
2022-01-25 14:41:55 +00:00
|
|
|
#endif
|
|
|
|
|
2021-04-30 19:47:33 +00:00
|
|
|
static GLfloat xrot; /* X Rotation */
|
|
|
|
static GLfloat yrot; /* Y Rotation */
|
|
|
|
static GLfloat xspeed; /* X Rotation Speed */
|
|
|
|
static GLfloat yspeed; /* Y Rotation Speed */
|
|
|
|
static GLfloat z = -5.0f; /* Depth Into The Screen */
|
2022-02-01 08:48:31 +00:00
|
|
|
GLboolean xp = GL_FALSE;
|
|
|
|
GLboolean yp = GL_FALSE;
|
|
|
|
GLboolean blend = GL_FALSE;
|
2021-04-30 19:47:33 +00:00
|
|
|
|
|
|
|
static GLuint filter; /* Which Filter To Use */
|
|
|
|
static GLuint texture[2]; /* Storage For Two Textures */
|
|
|
|
|
|
|
|
/* Load a PVR texture - located in pvr-texture.c */
|
|
|
|
extern GLuint glTextureLoadPVR(char *fname, unsigned char isMipMapped, unsigned char glMipMap);
|
|
|
|
|
2022-02-01 08:48:31 +00:00
|
|
|
/* A general OpenGL initialization function. Sets all of the initial parameters. */
|
|
|
|
void InitGL(int Width, int Height) // We call this right after our OpenGL window is created.
|
|
|
|
{
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
|
|
|
gluPerspective(45.0f, (GLfloat)Width/(GLfloat)Height, 0.1f, 100.0f);
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadIdentity();
|
|
|
|
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
glShadeModel(GL_SMOOTH);
|
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
|
|
|
|
glClearDepth(1.0f);
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glDepthFunc(GL_LEQUAL);
|
|
|
|
|
|
|
|
glColor4f(1.0f, 1.0f, 1.0f, 0.5);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
|
|
|
|
|
|
|
/* Enable Lighting and GL_LIGHT0 */
|
|
|
|
glEnable(GL_LIGHTING);
|
|
|
|
glEnable(GL_LIGHT0);
|
|
|
|
|
|
|
|
/* Set up the textures */
|
|
|
|
texture[0] = glTextureLoadPVR(IMG_PATH, 0, 0);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
|
|
|
|
texture[1] = glTextureLoadPVR(IMG_PATH, 0, 0);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrawGLScene(void) {
|
2021-04-30 19:47:33 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
glLoadIdentity();
|
|
|
|
glTranslatef(0.0f, 0.0f, z);
|
|
|
|
|
|
|
|
glRotatef(xrot, 1.0f, 0.0f, 0.0f);
|
|
|
|
glRotatef(yrot, 0.0f, 1.0f, 0.0f);
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texture[filter]);
|
|
|
|
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
/* Front Face */
|
|
|
|
glNormal3f(0.0f, 0.0f, 1.0f);
|
|
|
|
glTexCoord2f(0.0f, 0.0f);
|
|
|
|
glVertex3f(-1.0f, -1.0f, 1.0f);
|
|
|
|
glTexCoord2f(1.0f, 0.0f);
|
|
|
|
glVertex3f(1.0f, -1.0f, 1.0f);
|
|
|
|
glTexCoord2f(1.0f, 1.0f);
|
|
|
|
glVertex3f(1.0f, 1.0f, 1.0f);
|
|
|
|
glTexCoord2f(0.0f, 1.0f);
|
|
|
|
glVertex3f(-1.0f, 1.0f, 1.0f);
|
|
|
|
/* Back Face */
|
|
|
|
glNormal3f(0.0f, 0.0f, -1.0f);
|
|
|
|
glTexCoord2f(1.0f, 0.0f);
|
|
|
|
glVertex3f(-1.0f, -1.0f, -1.0f);
|
|
|
|
glTexCoord2f(1.0f, 1.0f);
|
|
|
|
glVertex3f(-1.0f, 1.0f, -1.0f);
|
|
|
|
glTexCoord2f(0.0f, 1.0f);
|
|
|
|
glVertex3f(1.0f, 1.0f, -1.0f);
|
|
|
|
glTexCoord2f(0.0f, 0.0f);
|
|
|
|
glVertex3f(1.0f, -1.0f, -1.0f);
|
|
|
|
/* Top Face */
|
|
|
|
glNormal3f(0.0f, 1.0f, 0.0f);
|
|
|
|
glTexCoord2f(0.0f, 1.0f);
|
|
|
|
glVertex3f(-1.0f, 1.0f, -1.0f);
|
|
|
|
glTexCoord2f(0.0f, 0.0f);
|
|
|
|
glVertex3f(-1.0f, 1.0f, 1.0f);
|
|
|
|
glTexCoord2f(1.0f, 0.0f);
|
|
|
|
glVertex3f(1.0f, 1.0f, 1.0f);
|
|
|
|
glTexCoord2f(1.0f, 1.0f);
|
|
|
|
glVertex3f(1.0f, 1.0f, -1.0f);
|
|
|
|
/* Bottom Face */
|
|
|
|
glNormal3f(0.0f, -1.0f, 0.0f);
|
|
|
|
glTexCoord2f(1.0f, 1.0f);
|
|
|
|
glVertex3f(-1.0f, -1.0f, -1.0f);
|
|
|
|
glTexCoord2f(0.0f, 1.0f);
|
|
|
|
glVertex3f(1.0f, -1.0f, -1.0f);
|
|
|
|
glTexCoord2f(0.0f, 0.0f);
|
|
|
|
glVertex3f(1.0f, -1.0f, 1.0f);
|
|
|
|
glTexCoord2f(1.0f, 0.0f);
|
|
|
|
glVertex3f(-1.0f, -1.0f, 1.0f);
|
|
|
|
/* Right face */
|
|
|
|
glNormal3f(1.0f, 0.0f, 0.0f);
|
|
|
|
glTexCoord2f(1.0f, 0.0f);
|
|
|
|
glVertex3f(1.0f, -1.0f, -1.0f);
|
|
|
|
glTexCoord2f(1.0f, 1.0f);
|
|
|
|
glVertex3f(1.0f, 1.0f, -1.0f);
|
|
|
|
glTexCoord2f(0.0f, 1.0f);
|
|
|
|
glVertex3f(1.0f, 1.0f, 1.0f);
|
|
|
|
glTexCoord2f(0.0f, 0.0f);
|
|
|
|
glVertex3f(1.0f, -1.0f, 1.0f);
|
|
|
|
/* Left Face */
|
|
|
|
glNormal3f(-1.0f, 0.0f, 0.0f);
|
|
|
|
glTexCoord2f(0.0f, 0.0f);
|
|
|
|
glVertex3f(-1.0f, -1.0f, -1.0f);
|
|
|
|
glTexCoord2f(1.0f, 0.0f);
|
|
|
|
glVertex3f(-1.0f, -1.0f, 1.0f);
|
|
|
|
glTexCoord2f(1.0f, 1.0f);
|
|
|
|
glVertex3f(-1.0f, 1.0f, 1.0f);
|
|
|
|
glTexCoord2f(0.0f, 1.0f);
|
|
|
|
glVertex3f(-1.0f, 1.0f, -1.0f);
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
xrot += xspeed;
|
|
|
|
yrot += yspeed;
|
2022-02-01 08:48:31 +00:00
|
|
|
|
|
|
|
/* Finish the frame */
|
|
|
|
glKosSwapBuffers();
|
2021-04-30 19:47:33 +00:00
|
|
|
}
|
|
|
|
|
2022-02-01 08:48:31 +00:00
|
|
|
int ReadController(void) {
|
2021-04-30 19:47:33 +00:00
|
|
|
#ifdef __DREAMCAST__
|
|
|
|
maple_device_t *cont;
|
|
|
|
cont_state_t *state;
|
|
|
|
|
2022-02-01 08:48:31 +00:00
|
|
|
cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);
|
2021-04-30 19:47:33 +00:00
|
|
|
|
2022-02-01 08:48:31 +00:00
|
|
|
/* Check key status */
|
|
|
|
state = (cont_state_t *)maple_dev_status(cont);
|
|
|
|
if(!state) {
|
|
|
|
printf("Error reading controller\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2021-04-30 19:47:33 +00:00
|
|
|
|
2022-02-01 08:48:31 +00:00
|
|
|
if(state->buttons & CONT_START)
|
|
|
|
return 0;
|
2021-04-30 19:47:33 +00:00
|
|
|
|
2022-02-01 08:48:31 +00:00
|
|
|
if(state->buttons & CONT_A)
|
|
|
|
z -= 0.02f;
|
2021-04-30 19:47:33 +00:00
|
|
|
|
2022-02-01 08:48:31 +00:00
|
|
|
if(state->buttons & CONT_B)
|
|
|
|
z += 0.02f;
|
2021-04-30 19:47:33 +00:00
|
|
|
|
2022-02-01 08:48:31 +00:00
|
|
|
if((state->buttons & CONT_X) && !xp) {
|
|
|
|
xp = GL_TRUE;
|
|
|
|
filter += 1;
|
2021-04-30 19:47:33 +00:00
|
|
|
|
2022-02-01 08:48:31 +00:00
|
|
|
if(filter > 1)
|
|
|
|
filter = 0;
|
|
|
|
}
|
2021-04-30 19:47:33 +00:00
|
|
|
|
2022-02-01 08:48:31 +00:00
|
|
|
if(!(state->buttons & CONT_X))
|
|
|
|
xp = GL_FALSE;
|
2021-04-30 19:47:33 +00:00
|
|
|
|
2022-02-01 08:48:31 +00:00
|
|
|
if((state->buttons & CONT_Y) && !yp) {
|
|
|
|
yp = GL_TRUE;
|
|
|
|
blend = !blend;
|
|
|
|
}
|
2021-04-30 19:47:33 +00:00
|
|
|
|
2022-02-01 08:48:31 +00:00
|
|
|
if(!(state->buttons & CONT_Y))
|
|
|
|
yp = GL_FALSE;
|
2021-04-30 19:47:33 +00:00
|
|
|
|
2022-02-01 08:48:31 +00:00
|
|
|
if(state->buttons & CONT_DPAD_UP)
|
|
|
|
xspeed -= 0.01f;
|
2021-04-30 19:47:33 +00:00
|
|
|
|
2022-02-01 08:48:31 +00:00
|
|
|
if(state->buttons & CONT_DPAD_DOWN)
|
|
|
|
xspeed += 0.01f;
|
2021-04-30 19:47:33 +00:00
|
|
|
|
2022-02-01 08:48:31 +00:00
|
|
|
if(state->buttons & CONT_DPAD_LEFT)
|
|
|
|
yspeed -= 0.01f;
|
2021-04-30 19:47:33 +00:00
|
|
|
|
2022-02-01 08:48:31 +00:00
|
|
|
if(state->buttons & CONT_DPAD_RIGHT)
|
|
|
|
yspeed += 0.01f;
|
|
|
|
#endif
|
2021-04-30 19:47:33 +00:00
|
|
|
|
2022-02-01 08:48:31 +00:00
|
|
|
/* Switch to the blended polygon list if needed */
|
|
|
|
if(blend) {
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glDepthMask(0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
glDepthMask(1);
|
|
|
|
}
|
2021-04-30 19:47:33 +00:00
|
|
|
|
2022-02-01 08:48:31 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2021-04-30 19:47:33 +00:00
|
|
|
|
2022-02-01 08:48:31 +00:00
|
|
|
int main(int argc, char **argv) {
|
|
|
|
printf("nehe08 beginning\n");
|
2021-04-30 19:47:33 +00:00
|
|
|
|
2022-02-01 08:48:31 +00:00
|
|
|
/* Get basic stuff initialized */
|
|
|
|
glKosInit();
|
2021-04-30 19:47:33 +00:00
|
|
|
|
2022-02-01 08:48:31 +00:00
|
|
|
InitGL(640, 480);
|
2021-04-30 19:47:33 +00:00
|
|
|
|
2022-02-01 08:48:31 +00:00
|
|
|
while(1) {
|
|
|
|
if (!ReadController())
|
|
|
|
break;
|
2021-04-30 19:47:33 +00:00
|
|
|
|
2022-02-01 08:48:31 +00:00
|
|
|
DrawGLScene();
|
2021-04-30 19:47:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|