pspgl - problem with GL_QUADS

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

Moderators: cheriff, TyRaNiD

Post Reply
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

pspgl - problem with GL_QUADS

Post by Jim »

I've knocked up the following test to show a problem with the GL_QUADS primitive

Code: Select all


#include <pspkernel.h>
#include <pspthreadman.h>
#include <pspiofilemgr.h>
#include <pspiofilemgr_dirent.h> 
#include <pspctrl.h>
#include <pspdisplay.h>
#include <pspdebug.h>
#include <psprtc.h>

#include <GLES/egl.h>
#include <GL/gl.h>

#include <stdlib.h>
#include <string.h>

/* Define the module info section */
PSP_MODULE_INFO&#40;"test", 0, 1, 1&#41;;

/* Define the main thread's attribute value &#40;optional&#41; */
PSP_MAIN_THREAD_ATTR&#40;THREAD_ATTR_USER&#41;;

static int done = 0;

/* Exit callback */
int exit_callback&#40;void&#41;
&#123;
	done = 1; 
	return 0;
&#125;

/* Callback thread */
void CallbackThread&#40;void *arg&#41;
&#123;
	int cbid;

	cbid = sceKernelCreateCallback&#40;"Exit Callback", &#40;void *&#41;exit_callback, NULL&#41;;
	sceKernelRegisterExitCallback&#40;cbid&#41;;

	sceKernelSleepThreadCB&#40;&#41;;
&#125;

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks&#40;void&#41;
&#123;
	int thid = 0;

	thid = sceKernelCreateThread&#40;"update_thread", &#40;void *&#41;CallbackThread, 0x11, 0xFA0, 0, 0&#41;;
	if&#40;thid >= 0&#41;
	&#123;
		sceKernelStartThread&#40;thid, 0, 0&#41;;
	&#125;

	return thid;
&#125;

static const EGLint attrib_list&#91;&#93;=
&#123;
	EGL_RED_SIZE, 1,
	EGL_GREEN_SIZE, 1,
	EGL_BLUE_SIZE, 1,
	EGL_ALPHA_SIZE, 0,
	EGL_DEPTH_SIZE, 0,
	EGL_NONE
&#125;;

EGLDisplay dpy;
EGLSurface surface;

static void init_egl&#40;void&#41;
&#123;
	EGLConfig config;
	EGLint num_configs;
	EGLContext ctx;

	dpy = eglGetDisplay&#40;0&#41;;
	eglInitialize&#40;dpy, NULL, NULL&#41;;

	eglChooseConfig&#40;dpy, attrib_list, &config, 1, &num_configs&#41;;

	if &#40;num_configs == 0&#41;
		return;

	ctx = eglCreateContext&#40;dpy, config, NULL, NULL&#41;;
	surface = eglCreateWindowSurface&#40;dpy, config, 0, NULL&#41;;
	eglMakeCurrent&#40;dpy, surface, surface, ctx&#41;;
&#125;

int main&#40;int argc, char **argv&#41;
&#123;
	SceCtrlData pad;

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

	init_egl&#40;&#41;;
	
	glShadeModel&#40;GL_SMOOTH&#41;;							// Enable Smooth Shading
	glClearColor&#40;0.0f, 0.0f, 0.0f, 1.0f&#41;;				// Black Background
	glDepthFunc&#40;GL_ALWAYS&#41;;
	glDisable&#40;GL_DEPTH_TEST&#41;;

	glClear&#40;GL_COLOR_BUFFER_BIT&#41;;

	//viewport in top left hand corner of window
	glMatrixMode&#40;GL_PROJECTION&#41;;
	glLoadIdentity&#40;&#41;;
	glOrthof&#40;0,640,480,0,-1,1&#41;;
	glMatrixMode&#40;GL_MODELVIEW&#41;;
	glLoadIdentity&#40;&#41;;
	glDrawBuffer&#40;GL_BACK&#41;;

	glViewport&#40;0,0,&#40;GLsizei&#41;480,&#40;GLsizei&#41;272&#41;;

	SetupCallbacks&#40;&#41;;

	glColor3ub&#40;255,255,255&#41;;

	do
	&#123;
		glBegin&#40;GL_QUADS&#41;;

		glVertex2i&#40;0,0&#41;;
		glVertex2i&#40;100,0&#41;;
		glVertex2i&#40;100,100&#41;;
		glVertex2i&#40;0,100&#41;;

		glVertex2i&#40;150+0,0&#41;;
		glVertex2i&#40;150+100,0&#41;;
		glVertex2i&#40;150+100,100&#41;;
		glVertex2i&#40;150+0,100&#41;;

		glEnd&#40;&#41;;

		glBegin&#40;GL_QUADS&#41;;

		glVertex2i&#40;0,150+0&#41;;
		glVertex2i&#40;100,150+0&#41;;
		glVertex2i&#40;100,150+100&#41;;
		glVertex2i&#40;0,150+100&#41;;

		glEnd&#40;&#41;;

		glBegin&#40;GL_QUADS&#41;;

		glVertex2i&#40;150+0,150+0&#41;;
		glVertex2i&#40;150+100,150+0&#41;;
		glVertex2i&#40;150+100,150+100&#41;;
		glVertex2i&#40;150+0,150+100&#41;;

		glEnd&#40;&#41;;

		eglSwapBuffers&#40;dpy, surface&#41;;

		sceCtrlReadBufferPositive&#40;&pad, 1&#41;; 

	&#125; while &#40;!pad.Buttons && !done&#41;;

	sceKernelExitGame&#40;&#41;;
	return 0;
&#125;
The problem is, unless I do a glBegin/End for each quad, they get linked together by an extra triangle. The sample code shows the problem. GL_TRIANGLES works fine however.
I'm using today's SVN pspgl.

Thanks in advance for any insight.

Jim
PeterM
Posts: 125
Joined: Sat Dec 31, 2005 7:25 pm
Location: Edinburgh, UK
Contact:

Post by PeterM »

I don't think quads are supported yet ( http://www.goop.org/psp/gl/#immediate ).
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

Oh, rats! I should have spotted that. Thanks Peter.

Jim
Post Reply