porting from sceGu openGL: help drawing Vertex arrays.

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

Moderators: cheriff, TyRaNiD

Post Reply
snowsquirrel
Posts: 51
Joined: Sun Feb 24, 2008 3:36 am

porting from sceGu openGL: help drawing Vertex arrays.

Post by snowsquirrel »

Trying to port my GU and GUM code to open GL. Most of the calls seem to map pretty well, but have a bit of trouble with my code for rendering a model.

I had this:

Code: Select all

	sceGumMatrixMode( GU_MODEL );
	sceGumLoadIdentity();
	sceGumTranslate( &pos );

	//set texture environment
	sceGuTexMode( GU_PSM_8888, 0, 0, 0 );
	sceGuTexFunc( GU_TFX_REPLACE, GU_TCC_RGB );
	sceGuTexFilter( GU_LINEAR, GU_LINEAR );
	sceGuTexScale( 1.0f, 1.0f );
	sceGuTexOffset( 0.0f, 0.0f );

	for&#40; int i=0; i < _numParts; i++ &#41;
	&#123;
		sceGuTexImage&#40; 0, 
			_parts&#91;i&#93;.texture->textureWidth, 
			_parts&#91;i&#93;.texture->textureHeight,
			_parts&#91;i&#93;.texture->textureWidth,
			&#40;void*&#41;_parts&#91;i&#93;.texture->data &#41;;
		sceGumDrawArray&#40; _renderMode, _renderFlags, _parts&#91;i&#93;.numVerts, 0, _parts&#91;i&#93;.vertex &#41;;
	&#125;
My port currently looks like this:

Code: Select all


	glMatrixMode&#40; GL_MODELVIEW &#41;;
	glLoadIdentity&#40;&#41;;
	glTranslatef&#40; v3_expand&#40;pos&#41; &#41;;

	glTexParameteri&#40; GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR &#41;;
	glTexParameteri&#40; GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR &#41;;
	glTexParameteri&#40; GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE &#41;;

	//sceGuTexScale&#40; 1.0f, 1.0f &#41;; // opengl version?
	//sceGuTexOffset&#40; 0.0f, 0.0f &#41;; // opengl version?
	glTexCoord&#40; 0.0f, 0.0f &#41;;

	for&#40; int i=0; i < _numParts; i++ &#41;
	&#123;
		//gen texture and bind them?
		glTexImage2d&#40;
				GL_TEXTURE_2D,
				0,
				4, // num color components?
				parts&#91;i&#93;.texture->textureWidth,
				parts&#91;i&#93;.texture->textureHeight,
				0,
				GL_RGBA,
				GL_UNSIGNED_BYTE,
				&#40;void*&#41;_parts&#91;i&#93;.texture->data &#41;;

		glVertexPointer&#40; 3, GL_FLOAT, sizeof&#40;Vertex&#41; - sizeof&#40;Vector3d&#41;, &&#40;_parts&#91;i&#93;.vertex&#91;0&#93;.coord&#41; &#41;;
		glTexCoordPoint&#40; 2, GL_FLOAT, sizeof&#40;Vertex&#41; - sizeof&#40;float&#41;*2, &&#40;_parts&#91;i&#93;.vertex&#91;0&#93;.u&#41; &#41;;
		glNormalPointer&#40; GL_FLOAT, sizeof&#40;Vertex&#41; - sizeof&#40;Vector3d&#41;, &&#40;_parts&#91;i&#93;.vertex&#91;0&#93;.normal&#41; &#41;;
		glColorPointer&#40; 4, GL_UNSIGNED_BYTE, sizeof&#40;Vertex&#41; - 4, &&#40;_parts&#91;i&#93;.vertex&#91;0&#93;.color&#41; &#41;;
		glDrawArrays&#40; GL_TRIANGLES, 0, _parts&#91;i&#93;.numVerts &#41;;
	&#125;
Do I have to do a glTexGen, and glTexBind to make the glTexImage2d work?
How does that drawing look?

In the middle of porting so code is not building at this momemnt.

Thanks for the help.

~S
bootdisk
Posts: 6
Joined: Tue Apr 29, 2008 12:00 am
Contact:

Post by bootdisk »

I don't know if this might be useful, but maybe looking at some psp emulators will help your porting the code.

And maybe using GLIntercept (http://www.opengl.org/sdk/tools/GLIntercept/) would let you know what your code is doing.

Regards,
---------------------------------------------------------
if you wanna survive you better learn how to lie
snowsquirrel
Posts: 51
Joined: Sun Feb 24, 2008 3:36 am

Post by snowsquirrel »

I would hope I don't have to go that deep. I am assuming this is pretty standard stuff I am doing, and that anyone who knows opengl would know the answer too. What is a decent PSP emulator?
~S
quadrizo
Posts: 21
Joined: Thu Aug 23, 2007 10:21 pm

Post by quadrizo »

you'd look at this tutorial : http://nehe.gamedev.net/data/lessons/le ... ?lesson=06
but in general you init a texture with :

Code: Select all

		
glGenTextures&#40;1, &texture&#41;;
glBindTexture&#40;GL_TEXTURE_2D, texture&#41;;
glTexImage2D&#40;GL_TEXTURE_2D,...
and use it with :

Code: Select all

		
glBindTexture&#40;GL_TEXTURE_2D, texture&#41;;
snowsquirrel
Posts: 51
Joined: Sun Feb 24, 2008 3:36 am

Post by snowsquirrel »

Thanks, for the reply.

Does binding the texture move it into vram? i.e, can I free the texture data from user memory after I am done gen/binding it? If so, is there a way to do the same with Ge?

Thanks,
~S
fungos
Posts: 41
Joined: Wed Oct 31, 2007 10:43 am
Location: cwb br
Contact:

Post by fungos »

About OpenGL, yes, binding a texture copy it to vga ram and you can safely free your resource (if you will not need load it again later).

About gu/gum I don't know, sorry.
snowsquirrel
Posts: 51
Joined: Sun Feb 24, 2008 3:36 am

Post by snowsquirrel »

Anyone know when the opengl equivilant of sceGuOffset(x,y)?
~S
Insert_witty_name
Posts: 376
Joined: Wed May 10, 2006 11:31 pm

Post by Insert_witty_name »

There's no need for the call in opengl.

In my emulator I have it stubbed in as:

Code: Select all

void sceGuOffset&#40;unsigned int x, unsigned int y&#41;
&#123;
	return;
&#125;
snowsquirrel
Posts: 51
Joined: Sun Feb 24, 2008 3:36 am

Post by snowsquirrel »

Is your emulator complete? Available for download? That might save me porting to OpenGL.
~S
Insert_witty_name
Posts: 376
Joined: Wed May 10, 2006 11:31 pm

Post by Insert_witty_name »

It's purely an emulator for my PSP engine snowsquirrel.

All I do is provide opengl function counterparts for the sceGu* and other function calls.

It's not complete at this time.

I would advise taking this route instead of writing specific opengl and GU counterparts for each of your functions.

That way if you create a new drawing function, it would be supported by both build environments from the start.

I will gladly share my work with you if you want to see it, just drop me a PM as I think it's falling away from the scope of this forum.
Post Reply