forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

porting from sceGu openGL: help drawing Vertex arrays.

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
snowsquirrel



Joined: 24 Feb 2008
Posts: 51

PostPosted: Mon Apr 28, 2008 10:55 am    Post subject: porting from sceGu openGL: help drawing Vertex arrays. Reply with quote

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:

   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( int i=0; i < _numParts; i++ )
   {
      sceGuTexImage( 0,
         _parts[i].texture->textureWidth,
         _parts[i].texture->textureHeight,
         _parts[i].texture->textureWidth,
         (void*)_parts[i].texture->data );
      sceGumDrawArray( _renderMode, _renderFlags, _parts[i].numVerts, 0, _parts[i].vertex );
   }


My port currently looks like this:
Code:


   glMatrixMode( GL_MODELVIEW );
   glLoadIdentity();
   glTranslatef( v3_expand(pos) );

   glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
   glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
   glTexParameteri( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );

   //sceGuTexScale( 1.0f, 1.0f ); // opengl version?
   //sceGuTexOffset( 0.0f, 0.0f ); // opengl version?
   glTexCoord( 0.0f, 0.0f );

   for( int i=0; i < _numParts; i++ )
   {
      //gen texture and bind them?
      glTexImage2d(
            GL_TEXTURE_2D,
            0,
            4, // num color components?
            parts[i].texture->textureWidth,
            parts[i].texture->textureHeight,
            0,
            GL_RGBA,
            GL_UNSIGNED_BYTE,
            (void*)_parts[i].texture->data );

      glVertexPointer( 3, GL_FLOAT, sizeof(Vertex) - sizeof(Vector3d), &(_parts[i].vertex[0].coord) );
      glTexCoordPoint( 2, GL_FLOAT, sizeof(Vertex) - sizeof(float)*2, &(_parts[i].vertex[0].u) );
      glNormalPointer( GL_FLOAT, sizeof(Vertex) - sizeof(Vector3d), &(_parts[i].vertex[0].normal) );
      glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(Vertex) - 4, &(_parts[i].vertex[0].color) );
      glDrawArrays( GL_TRIANGLES, 0, _parts[i].numVerts );
   }


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
Back to top
View user's profile Send private message
bootdisk



Joined: 29 Apr 2008
Posts: 6

PostPosted: Tue Apr 29, 2008 12:08 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
snowsquirrel



Joined: 24 Feb 2008
Posts: 51

PostPosted: Tue Apr 29, 2008 12:13 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
quadrizo



Joined: 23 Aug 2007
Posts: 21

PostPosted: Tue Apr 29, 2008 12:27 am    Post subject: Reply with quote

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

Code:
      
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D,...


and use it with :
Code:
      
glBindTexture(GL_TEXTURE_2D, texture);
Back to top
View user's profile Send private message
snowsquirrel



Joined: 24 Feb 2008
Posts: 51

PostPosted: Tue Apr 29, 2008 8:27 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
fungos



Joined: 31 Oct 2007
Posts: 41
Location: cwb br

PostPosted: Tue Apr 29, 2008 9:59 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
snowsquirrel



Joined: 24 Feb 2008
Posts: 51

PostPosted: Sun May 04, 2008 2:56 am    Post subject: Reply with quote

Anyone know when the opengl equivilant of sceGuOffset(x,y)?
~S
Back to top
View user's profile Send private message
Insert_witty_name



Joined: 10 May 2006
Posts: 376

PostPosted: Sun May 04, 2008 3:33 am    Post subject: Reply with quote

There's no need for the call in opengl.

In my emulator I have it stubbed in as:

Code:
void sceGuOffset(unsigned int x, unsigned int y)
{
   return;
}
Back to top
View user's profile Send private message
snowsquirrel



Joined: 24 Feb 2008
Posts: 51

PostPosted: Sun May 04, 2008 8:38 am    Post subject: Reply with quote

Is your emulator complete? Available for download? That might save me porting to OpenGL.
~S
Back to top
View user's profile Send private message
Insert_witty_name



Joined: 10 May 2006
Posts: 376

PostPosted: Sun May 04, 2008 8:54 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group