PSPGL Quad Implementation

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

Moderators: cheriff, TyRaNiD

Post Reply
stinkymeat
Posts: 10
Joined: Tue Oct 18, 2005 6:47 pm

PSPGL Quad Implementation

Post by stinkymeat »

I'm having some problems with my code that is a modified version of the glut example for PSPgl. The main problem is that the code for drawing a triangle works, but its counterpart, the square, doesnt seem to work. As you can see from the code below, both are present, with the triangle code commented out. This code works. The quad code doesnt. I get zero compile errors, but the result on the PSP is a black screen :(

Code snippet in question:

Code: Select all

   GLCHK(glClear(GL_COLOR_BUFFER_BIT));
   GLCHK(glBegin(GL_QUADS));                                              // Draw A Quad
      GLCHK(glColor3f(1.0f, 1.0f, 1.0f)); GLCHK(glVertex3f(-1.0f, 1.0f, 0.0f));   // Top Left
      GLCHK(glColor3f(1.0f, 1.0f, 1.0f)); GLCHK(glVertex3f( 1.0f, 1.0f, 0.0f));   // Top Right
      GLCHK(glColor3f(1.0f, 1.0f, 1.0f)); GLCHK(glVertex3f( 1.0f,-1.0f, 0.0f));   // Bottom Right
      GLCHK(glColor3f(1.0f, 1.0f, 1.0f)); GLCHK(glVertex3f(-1.0f,-1.0f, 0.0f));   // Bottom Left
   GLCHK(glEnd());                                                         // Done Drawing The Quad

The whole code:

Code: Select all

#include <stdlib.h>
#include <GL/glut.h>


/******* PSP specific debugging ********************************************/
extern void __psp_log &#40;const char *fmt, ...&#41;;

/* enable GLerror logging to "ms0&#58;/log.txt" */
#if 1
	#define GLCHK&#40;x&#41;						\
	do &#123;								\
		GLint errcode;						\
		x;							\
		errcode = glGetError&#40;&#41;;					\
		if &#40;errcode != GL_NO_ERROR&#41; &#123;				\
			__psp_log&#40;"%s &#40;%d&#41;&#58; GL error 0x%04x\n",		\
				__FUNCTION__, __LINE__,			\
				&#40;unsigned int&#41; errcode&#41;;		\
		&#125;							\
	&#125; while &#40;0&#41;
#else
	#define GLCHK&#40;x&#41; x
#endif
/******* end of PSP specific debugging *************************************/


static
void reshape &#40;int w, int h&#41;
&#123;
	GLCHK&#40;glViewport&#40;0, 0, w, h&#41;&#41;;
	GLCHK&#40;glMatrixMode&#40;GL_PROJECTION&#41;&#41;;
	GLCHK&#40;glLoadIdentity&#40;&#41;&#41;;
	GLCHK&#40;glOrtho&#40;-2, 2, -2, 2, -2, 2&#41;&#41;;
	GLCHK&#40;glMatrixMode&#40;GL_MODELVIEW&#41;&#41;;
	GLCHK&#40;glLoadIdentity&#40;&#41;&#41;;
&#125;


static float delta = 1.0;

static
void display &#40;void&#41;
&#123;
	static GLfloat angle;
	angle += delta;

	GLCHK&#40;glMatrixMode&#40;GL_MODELVIEW&#41;&#41;;
	GLCHK&#40;glLoadIdentity&#40;&#41;&#41;;
	
//	GLCHK&#40;glTranslatef&#40;0.0f, 0.0f, -2.5f&#41;&#41;;
//	GLCHK&#40;glRotatef&#40;angle * 0.79f, 1.0f, 0.0f, 0.0f&#41;&#41;;
//	GLCHK&#40;glRotatef&#40;angle * 0.98f, 0.0f, 1.0f, 0.0f&#41;&#41;;
//	GLCHK&#40;glRotatef&#40;angle * 1.32f, 0.0f, 0.0f, 1.0f&#41;&#41;;

	GLCHK&#40;glShadeModel&#40;GL_SMOOTH&#41;&#41;;
	
	GLCHK&#40;glClear&#40;GL_COLOR_BUFFER_BIT&#41;&#41;;
	GLCHK&#40;glBegin&#40;GL_QUADS&#41;&#41;;						  						 	    // Draw A Quad
		GLCHK&#40;glColor3f&#40;1.0f, 1.0f, 1.0f&#41;&#41;; GLCHK&#40;glVertex3f&#40;-1.0f, 1.0f, 0.0f&#41;&#41;;	// Top Left
		GLCHK&#40;glColor3f&#40;1.0f, 1.0f, 1.0f&#41;&#41;; GLCHK&#40;glVertex3f&#40; 1.0f, 1.0f, 0.0f&#41;&#41;;	// Top Right
		GLCHK&#40;glColor3f&#40;1.0f, 1.0f, 1.0f&#41;&#41;; GLCHK&#40;glVertex3f&#40; 1.0f,-1.0f, 0.0f&#41;&#41;;	// Bottom Right
		GLCHK&#40;glColor3f&#40;1.0f, 1.0f, 1.0f&#41;&#41;; GLCHK&#40;glVertex3f&#40;-1.0f,-1.0f, 0.0f&#41;&#41;;	// Bottom Left
	GLCHK&#40;glEnd&#40;&#41;&#41;;		  									  			  			// Done Drawing The Quad

	/*
	GLCHK&#40;glClear&#40;GL_COLOR_BUFFER_BIT&#41;&#41;;
	GLCHK&#40;glBegin&#40;GL_TRIANGLES&#41;&#41;;
		GLCHK&#40;glColor3f&#40;1.0f, 1.0f, 1.0f&#41;&#41;; GLCHK&#40;glVertex3f&#40;1.0f, 0.0f, 0.0f&#41;&#41;;
		GLCHK&#40;glColor3f&#40;1.0f, 1.0f, 1.0f&#41;&#41;; GLCHK&#40;glVertex3f&#40;0.0f, 1.0f, 0.0f&#41;&#41;;
		GLCHK&#40;glColor3f&#40;1.0f, 1.0f, 1.0f&#41;&#41;; GLCHK&#40;glVertex3f&#40;0.0f, 0.0f, 1.0f&#41;&#41;;
	GLCHK&#40;glEnd&#40;&#41;&#41;;
	*/
	
	glutSwapBuffers&#40;&#41;;
	glutPostRedisplay&#40;&#41;;
&#125;

int main&#40;int argc, char* argv&#91;&#93;&#41;
&#123;
	glutInit&#40;&argc, argv&#41;;
	glutCreateWindow&#40; __FILE__ &#41;;
	glutReshapeFunc&#40;reshape&#41;;
	glutDisplayFunc&#40;display&#41;;
	glutMainLoop&#40;&#41;;
	return 0;
&#125;

jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Re: PSPGL Quad Implementation

Post by jsgf »

stinkymeat wrote:I'm having some problems with my code that is a modified version of the glut example for PSPgl. The main problem is that the code for drawing a triangle works, but its counterpart, the square, doesnt seem to work. As you can see from the code below, both are present, with the triangle code commented out. This code works. The quad code doesnt. I get zero compile errors, but the result on the PSP is a black screen :(
Quads aren't implemented. Use a triangle fan, it should just drop in (replace QUADS with TRIANGLE_FAN); obviously it won't work if you want to draw more than one per begin/end.
Post Reply