Exemplo n.º 1
0
int main(int argc, char **argv) {
    maple_device_t *cont;
    cont_state_t *state;
    float   r = 0.0f;
    float   dr = 2.0f;
    float   z = -14.0f;
    GLuint  texture;
    int trans = 0;

    /* Initialize KOS */
    dbglog_set_level(DBG_WARNING);
    pvr_init_defaults();

    printf("gltest beginning\n");

    /* Get basic stuff initialized */
    glKosInit();
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f, vid_mode->width / (GLfloat)vid_mode->height, 0.1f, 100.0f);
    glMatrixMode(GL_MODELVIEW);
    glEnable(GL_TEXTURE_2D);

    /* Expect CW vertex order */
    glFrontFace(GL_CW);

    /* Enable Transparancy */
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    /* Load a texture and make it look nice */
    loadtxr("/rd/glass.pvr", &texture);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_FILTER, GL_FILTER_BILINEAR);
    glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATEALPHA);


    printf("texture is %08x\n", texture);

    Cube *cubes[4] = {
        new Cube(-5.0f, 0.0f, 0.0f),
        new Cube(5.0f, 0.0f, 0.0f),
        new Cube(0.0f, 5.0f, 0.0f),
        new Cube(0.0f, -5.0f, 0.0f)
    };
    cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);

    while(1) {
        /* Check key status */
        state = (cont_state_t *)maple_dev_status(cont);

        if(!state) {
            printf("Error reading controller\n");
            break;
        }

        if(state->buttons & CONT_START)
            break;

        if(state->buttons & CONT_DPAD_UP)
            z -= 0.1f;

        if(state->buttons & CONT_DPAD_DOWN)
            z += 0.1f;

        if(state->buttons & CONT_DPAD_LEFT) {
            /* If manual rotation is requested, then stop
               the automated rotation */
            dr = 0.0f;

            for(int i = 0; i < 4; i++)
                cubes[i]->rotate(- 2.0f);

            r -= 2.0f;
        }

        if(state->buttons & CONT_DPAD_RIGHT) {
            dr = 0.0f;

            for(int i = 0; i < 4; i++)
                cubes[i]->rotate(+ 2.0f);

            r += 2.0f;
        }

        if(state->buttons & CONT_A) {
            /* This weird logic is to avoid bouncing back
               and forth before the user lets go of the
               button. */
            if(!(trans & 0x1000)) {
                if(trans == 0)
                    trans = 0x1001;
                else
                    trans = 0x1000;
            }
        }
        else {
            trans &= ~0x1000;
        }

        for(int i = 0; i < 4; i++)
            cubes[i]->rotate(dr);

        r += dr;

        /* Draw four objects */
        glLoadIdentity();
        glTranslatef(0.0f, 0.0f, z);
        glRotatef(r, 0.0f, 1.0f, 0.5f);

        cubes[0]->draw();
        cubes[1]->draw();

        /* Potentially do two as translucent */
        if(trans & 1) {
            glEnable(GL_BLEND);
            glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
            glDisable(GL_CULL_FACE);
        }

        cubes[2]->draw();
        cubes[3]->draw();

        if(trans & 1) {
            glEnable(GL_CULL_FACE);
			glDisable(GL_BLEND);
        }

        /* Finish the frame */
        glutSwapBuffers();            
    }

    for(int i = 0; i < 4; i++)
        delete cubes[i];

	glDeleteTextures(1, &texture);

    return 0;
}
Exemplo n.º 2
0
int main(int argc, char **argv) {
	cont_cond_t cond;
	uint8	c;
	GLboolean yp = GL_FALSE;

	/* Initialize KOS */
        pvr_init(&params);

	printf("nehe09 beginning\n");

	/* Get basic stuff initialized */
	glKosInit();

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0f,640.0f/480.0f,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);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE);
	//glEnable(GL_BLEND);

	for (loop=0; loop<NUM_STARS; loop++)
	{
		star[loop].angle=0.0f;
		star[loop].dist=((float)(loop)/NUM_STARS)*5.0f;
		star[loop].r=rand()%256;
		star[loop].g=rand()%256;
		star[loop].b=rand()%256;
	}

	/* Set up the texture */
	loadtxr("/rd/Star.pcx", &texture[0]);

	c = maple_first_controller();
	while(1) {
		/* Check key status */
		if (cont_get_cond(c, &cond) < 0) {
			printf("Error reading controller\n");
			break;
		}
		if (!(cond.buttons & CONT_START))
			break;
		if (!(cond.buttons & CONT_DPAD_UP))
			tilt -= 0.5f;
		if (!(cond.buttons & CONT_DPAD_DOWN))
			tilt += 0.5f;
		if (!(cond.buttons & CONT_A))
			zoom -= 0.2f;
		if (!(cond.buttons & CONT_B))
			zoom += 0.2f;
		if (!(cond.buttons & CONT_Y) && !yp) {
			yp = GL_TRUE;
			twinkle = !twinkle;
		}
		if (cond.buttons & CONT_Y)
			yp = GL_FALSE;

		/* Begin frame */
		glKosBeginFrame();

		/* Switch to blended polygon list */
		glKosFinishList();

		/* Draw the GL "scene" */
		draw_gl();

		/* Finish the frame */
		glKosFinishFrame();
	}

	return 0;
}
Exemplo n.º 3
0
int main(int argc, char **argv) {
	cont_cond_t cond;
	uint8	c;
	float	r = 0.0f;
	float	dr = 2;
	float	z = -14.0f;
	GLuint	texture;
	GLuint  dummy;
	int	trans = 0;
	pvr_stats_t	stats;

	/* Initialize KOS */

	/* Use this to test other video modes */
	/* vid_init(DM_320x240, PM_RGB565); */

	/* Normal init */
	pvr_init(&params);

	printf("gltest beginning\n");

	/* Get basic stuff initialized */
	glKosInit();
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0f, 640.0f / 480.0f, 0.1f, 100.0f);
	glMatrixMode(GL_MODELVIEW);
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_KOS_AUTO_UV);

	/* Expect CW verts */
	glFrontFace(GL_CW);

        /* Enable Transparancy */
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	
	/* Load a texture and make to look nice */
	loadtxr("/rd/crate.pcx", &texture);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_FILTER, GL_FILTER_BILINEAR);
        glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATEALPHA);

	glClearColor(0.3f, 0.4f, 0.5f, 1.0f);

	while(1) {
		/* Check key status */
		c = maple_first_controller();
		if (c) {
			if (cont_get_cond(c, &cond) < 0) {
				printf("Error reading controller\n");
			}
			if (!(cond.buttons & CONT_START))
				break;
			if (!(cond.buttons & CONT_DPAD_UP))
				z -= 0.1f;
			if (!(cond.buttons & CONT_DPAD_DOWN))
				z += 0.1f;
			if (!(cond.buttons & CONT_DPAD_LEFT)) {
				/* If manual rotation is requested, then stop
				   the automated rotation */
				dr = 0.0f;
				r -= 2.0f;
			}
			if (!(cond.buttons & CONT_DPAD_RIGHT)) {
				dr = 0.0f;
				r += 2.0f;
			}
			if (!(cond.buttons & CONT_A)) {
				/* This weird logic is to avoid bouncing back
				   and forth before the user lets go of the
				   button. */
				if (!(trans & 0x1000)) {
					if (trans == 0)
						trans = 0x1001;
					else
						trans = 0x1000;
				}
			} else {
				trans &= ~0x1000;
			}
		}

		r += dr;

		/* Begin frame */
		glKosBeginFrame();

		/* Draw four cubes */
		glLoadIdentity();
		glTranslatef(0.0f, 0.0f, z);
		glRotatef(r, 0.0f, 1.0f, 0.5f);
		glPushMatrix();
		
		glTranslatef(-5.0f, 0.0f, 0.0f);
		cube(r);

		glPopMatrix();
		glPushMatrix();
		glTranslatef(5.0f, 0.0f, 0.0f);
		cube(r);

		/* Potentially do two as translucent */
		if (trans & 1) {
			glKosFinishList();
			glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
			glDisable(GL_CULL_FACE);
		}

		glPopMatrix();
		glPushMatrix();
		glTranslatef(0.0f, 5.0f, 0.0f);
		cube(r);

		glPopMatrix();
		glTranslatef(0.0f, -5.0f, 0.0f);
		cube(r);

		if (trans & 1) {
		        glEnable(GL_CULL_FACE);
		}

		/* Finish the frame */
		glKosFinishFrame();
	}

	pvr_get_stats(&stats);
	printf("VBL Count: %d, last_time: %f, frame rate: %f fps\n",
		stats.vbl_count, stats.frame_last_time, stats.frame_rate);

	return 0;
}
Exemplo n.º 4
0
int main(int argc, char **argv) {
	cont_cond_t cond;
	uint8	c;
	int     trans = 0;
	GLuint	texture1, texture2, texture3;

	/* Initialize KOS */
        pvr_init(&params);

	printf("texenv beginning\n");

	/* Get basic stuff initialized */
	glKosInit();
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glOrtho(0,640,0,480,0,-1);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	glEnable(GL_TEXTURE_2D);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glDepthMask(GL_FALSE);

	/* Set up the textures */
	loadtxr("/rd/checker.pcx", &texture1);
	loadtxr("/rd/crate.pcx", &texture2);
	loadtxr_tga("/rd/kgl.tga", &texture3);

	c = maple_first_controller();
	while(1) {
		/* Check key status */
		if (cont_get_cond(c, &cond) < 0) {
			printf("Error reading controller\n");
			break;
		}
		if (!(cond.buttons & CONT_START))
			break;
		if (!(cond.buttons & CONT_A)) {
			/* This weird logic is to avoid bouncing back
			   and forth before the user lets go of the
			   button. */
			if (!(trans & 0x1000)) {
				if (trans == 0)
					trans = 0x1001;
				else
					trans = 0x1000;
			}
		} else {
			trans &= ~0x1000;
		}

		/* Begin frame */
		glKosBeginFrame();

		glDisable(GL_KOS_AUTO_UV);
		glBindTexture(GL_TEXTURE_2D, texture1);
		glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE);
		glColor4f(0,0,0,0);
		glBegin(GL_QUADS);
		glTexCoord2f(0,0);
		glVertex3f(0,0,0);
		glTexCoord2f(20,0);
		glVertex3f(640,0,0);
		glTexCoord2f(20,15);
		glVertex3f(640,480,0);
		glTexCoord2f(0,15);
		glVertex3f(0,480,0);
		glEnd();

		if (trans & 1) {
			glKosFinishList();
		}

		/* top row, non-alpha texture */
		glEnable(GL_KOS_AUTO_UV);
		glBindTexture(GL_TEXTURE_2D, texture2);
		glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE);
		quad(5,250);

		glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);
		quad(165,250);

		glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_DECAL);
		quad(325,250);

		glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATEALPHA);
		quad(485,250);

		/* bottom row, alpha texture */
		glBindTexture(GL_TEXTURE_2D, texture3);
		glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE);
		quad(5,50);

		glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);
		quad(165,50);

		glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_DECAL);
		quad(325,50);

		glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATEALPHA);
		quad(485,50);

		/* Finish the frame */
		glKosFinishFrame();
	}

	return 0;
}
Exemplo n.º 5
0
bool Texture::load(std::string strFn)
{
	setId(strFn);
	//Create texture
	//		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img.width, img.height, 0, img.format, GL_UNSIGNED_BYTE, img.data);	
#ifdef ARCH_PSP
	const char *filename = strFn.c_str();
	
	int filenameLength=strlen(filename);
   
	if(	strncmp((filename+filenameLength-3), "TGA", 3)==0 ||
	   strncmp((filename+filenameLength-3), "tga", 3)==0)
		{
   			Logger::log("[Texture:%s] Loading....",strFn.c_str());
   
   			if( !psp_texture.LoadTGA((char *)strFn.c_str()) )
   			{
   				Logger::log(LOG_ERROR,"failed!\n");
   				//sceKernelExitGame();
				return false;
   			}
   			else
   			{
   				Logger::log("ok.");
				return true;
   			}
   			psp_texture.Swizzle();
   			Logger::log("\n");
	}

#else
	bool isJpgTexture = false;
	
	if(	strncmp((strFn.c_str()+strFn.length()-3), "JPG", 3)==0 ||
	   strncmp((strFn.c_str()+strFn.length()-3), "jpg", 3)==0)
		isJpgTexture = true;

	bool imgLoaded = false;
		
#ifdef ARCH_DC

	const char *filename = strFn.c_str();
	
	int filenameLength=strlen(filename);
	
	if(	strncmp((filename+filenameLength-3), "PCX", 3)==0 ||
	   strncmp((filename+filenameLength-3), "pcx", 3)==0)
		{
			Logger::log("Loading PCX using dreamcast loader");
			generate();
			
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_FILTER, GL_FILTER_BILINEAR);
			loadtxr(filename, &glTexId);
			return true;
		}
	else if(	strncmp((filename+filenameLength-3), "PVR", 3)==0 ||
	   strncmp((filename+filenameLength-3), "pvr", 3)==0)
		{
			Logger::log("Loading PVR using dreamcast loader\n");
			generate();
			
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_FILTER, GL_FILTER_BILINEAR);
			loadpvr(filename, &glTexId);
			return true;
		}	
#endif
	
	imgLoaded = img.Load((char *)strFn.c_str());
	
	if (imgLoaded)
	{
		generate();
		glEnable(GL_TEXTURE_2D);

#ifdef OPENGL_ES
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
#endif
#ifdef ARCH_DC
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
#endif
		
#if !defined(ARCH_DC) && !defined(OPENGL_ES) && !defined(ARCH_PSP)
		glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
#endif

#ifndef ARCH_DC
		if(isJpgTexture)
			glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
#endif

		format = img.format;
		alpha = (format==GL_RGBA)?true:false;
		
		glTexImage2D(GL_TEXTURE_2D, 0, img.format, img.width, img.height, 0, img.format, GL_UNSIGNED_BYTE, img.data);	

#ifndef ARCH_DC
		if(isJpgTexture)
			glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
#endif


		return true;
	}
	else
	{
		return false;
	}
#endif
//	char c = toupper(strFn[strFn.length()-3]);
//			
//	if (c == 'T')
//	{
//		load(strFn,FORMAT_TGA);
//	}
//	else 
//	if (c == 'P')
//	{
//		load(strFn,FORMAT_PNG);
//	}
}