sceGuDrawArray Emulation

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

Moderators: cheriff, TyRaNiD

Post Reply
Sonicadvance1
Posts: 10
Joined: Thu Oct 13, 2005 8:35 am

sceGuDrawArray Emulation

Post by Sonicadvance1 »

Right now I'm working on a project, and I need to emulate sceGuDrawArray in OpenGL, but I think I need to convert the vertex and draw it. Only problem is, I can't seem to get it to work. Right now I'm just trying to get vertices to draw and just skipping indices at the moment, also, I'm working with lines only right now so I am not doing anything to draw triangles or quads.
The code below is what I currently have and it looks really ugly because of my constant fiddling with it :D

Code: Select all

void sceGuDrawArray(int prim, int vtype, int count, const void* indices, const void* vertices)

{
	unsigned int *n=malloc((count)*3*sizeof(int));
	int i=0, a=0;
	for&#40;a=0;a<count;a+=3,i++&#41;&#123;
		n&#91;a&#93;=&#40;&#40;Vertex*&#41;vertices&#41;&#91;i&#93;.x;
		n&#91;a+1&#93;=&#40;&#40;Vertex*&#41;vertices&#41;&#91;i&#93;.y;
		n&#91;a+2&#93;=&#40;&#40;Vertex*&#41;vertices&#41;&#91;i&#93;.z;
	&#125;

	if&#40;indices!=0&#41;
		glDrawRangeElements&#40;  GL_MAX_ELEMENTS_INDICES, 0,count, count, vtype+1,indices &#41;;
	if&#40;vertices!=0&#41;&#123;
		glDrawElements&#40;GL_LINE_STRIP,count, GL_UNSIGNED_INT,n &#41;;

	&#125;
	while&#40;&#40;&#40;unsigned char*&#41;vertices&#41;&#91;i&#93;!=0&#41;&#123;
		printf&#40;"X=%d\tY=%d\tZ=%d\n",&#40;&#40;Vertex*&#41;vertices&#41;&#91;i&#93;.x,&#40;&#40;Vertex*&#41;vertices&#41;&#91;i&#93;.y,&#40;&#40;Vertex*&#41;vertices&#41;&#91;i&#93;.z&#41;;
		i++;
	&#125;
&#125;
siberianstar
Posts: 70
Joined: Thu Jun 22, 2006 9:24 pm

Post by siberianstar »

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

Post by PeterM »

Hello,

I don't know what isn't working, but here are some suggestions:

* You may need to convert the vertices to a format supported by OpenGL (whatever is represented by vtype -> GL_FLOAT). 2D vertices will be difficult.
* Make sure the primitive type is converted to one which GL recognises. Have fun with sprites...
* Try not to malloc for every draw - allocate a buffer elsewhere and reuse it. And always free what you malloc.
Post Reply