shamino: my implementation of ms3d va

This is a discussion on shamino: my implementation of ms3d va within the Game Programming forums, part of the General Programming Boards category; Shamino, I never showed you my implementation of ms3d vertex arrays. I decided to post it in public in case ...

  1. #1

    Join Date
    May 2005
    Posts
    1,041

    shamino: my implementation of ms3d va

    Shamino, I never showed you my implementation of ms3d vertex arrays. I decided to post it in public in case anybody else wanted to see what it might look like.

    As usual, my code is messy, but it works.

    Instead of trying to explain each aspect of the code, I will just wait for any questions.

    In general, the idea is to only store a single copy of each vertex, then create parallel index arrays so OpenGL can render it fast and efficiently.

    This can very easily be used as the only centralized format, where anything else must get converted to this before it can be used.

    In the screenshot at the folder, the model being rendered with the red sphere around it is rendering a ms3d model (in its inefficient format), whilst the other one without the red thing around it is being rendered as a tightly packed vertex array.
    ihatenature.thejefffiles.com/shamino


    Once all of that stuff is compiled, here are some constructs that I use to render it.

    Code:
    struct	NT_MODEL_CONTAINER
    {
    	NT_MODEL_CONTAINER(NT_MODEL & mdl) : mdl_ref(mdl) {}
    	float	mat[16];
    	NT_MODEL	&mdl_ref;
    };
    ...
    	void	AddNTModelToRenderer(NT_MODEL	 & mdl,Matrix4x4	& mat)
    	{
    		NT_MODEL_CONTAINER	*temp = new NT_MODEL_CONTAINER(mdl);
    		mat.FillGLMatrix(temp->mat);
    		mvNTModels.push_back(temp);
    	}
    ...
    void	GLRenderer::RenderNTModels()
    {
    	if(!mvNTModels.size())
    	{
    		return;
    	}
    	
    	NT_GL(glDisable(GL_LIGHTING))
    	NT_GL(glColor3f(1.0f,1.0f,1.0f))
    	NT_GL(glDepthFunc(GL_LESS))		
    
    	gpNTGLAPI->glActiveTextureARB(GL_TEXTURE1_ARB);
    	NT_GL(glDisable(GL_TEXTURE_2D))	//disable second texture unit
    	
    	gpNTGLAPI->glActiveTextureARB(GL_TEXTURE0_ARB);
    	NT_GL(glEnable(GL_TEXTURE_2D)) //enable first texture unit
    	NT_GL(glEnableClientState(GL_TEXTURE_COORD_ARRAY))		//enable texture coord array for the first texture unit
    	
    	NT_GL(glEnable(GL_CULL_FACE))	
    	R_NormalCullMode();
    	
    	NT_GL(glEnableClientState(GL_VERTEX_ARRAY))
    	NT_GL(glEnableClientState(GL_TEXTURE_COORD_ARRAY))
    		
    	gpNTGLAPI->glClientActiveTextureARB(GL_TEXTURE0_ARB)
    	NT_GL(glEnableClientState(GL_TEXTURE_COORD_ARRAY))	
    
    
    	std::vector<NT_MODEL_CONTAINER*>::iterator	ptr;
    	NT_MODEL_CONTAINER	*pObject = 0;
    	for(ptr = mvNTModels.begin(); ptr != mvNTModels.end(); ptr++)
    	{
    		pObject	=	*ptr;
    		NT_MODEL  & mdl_ref = pObject->mdl_ref;
    		NT_GL(glPushMatrix())
    		NT_GL(glMultMatrixf(pObject->mat))	//transform the model
    		
    		//render each mesh 
    		for(int i = 0; i < mdl_ref.mNumMeshes; i++)
    		{
    			NT_MODEL::NT_MESH & mesh_ref = mdl_ref.mpMeshes[i];
    			
    			gpTextureManager->BindTexture(GL_TEXTURE_2D,mdl_ref.mpTextures[mesh_ref.mTextureIndex]);
    					
    #define	USE_NT_INDEX_ARRAY	1
    
    #if	USE_NT_INDEX_ARRAY
    			int	start_index = mdl_ref.mpIndexArray[mesh_ref.mStartVertIndex];
    			int	start_index = mesh_ref.mStartVertIndex;	
    
    			NT_GL(glVertexPointer(3,GL_FLOAT,sizeof(NT_VERTEX),&mdl_ref.mpVertices[start_index].vertex))
    			NT_GL(glTexCoordPointer(2,GL_FLOAT,sizeof(NT_VERTEX),&mdl_ref.mpVertices[start_index].tex_coord))
    			NT_GL(glDrawElements(GL_TRIANGLES,mesh_ref.mNumMeshVerts,GL_UNSIGNED_INT,&mdl_ref.mpIndexArray[mesh_ref.mStartMeshIndex]))
    #else
    			//alternative to the method above (immediate mode, both work)
    			gpNTGLAPI->ntglBegin(GL_TRIANGLES);		
    			//I've used this method of accessing data for immediate mode rendering, works fine
    			for(int  tri = 0; tri < mesh_ref.mNumMeshVerts; tri += 3) //reference to NT_MODEL::NT_MESH
    			{	
    				for(int vert = 0; vert < 3; vert++)	//3 verts in a triangle
    				{
    					int	index = mdl_ref.mpIndexArray[tri + vert + mesh_ref.mStartMeshIndex];
    					
    					NT_VERTEX	&	vert_ref = mdl_ref.mpVertices[index];
    					gpNTGLAPI->ntglTexCoord2fv(vert_ref.tex_coord);
    					gpNTGLAPI->ntglVertex3fv(vert_ref.vertex);
    				}	
    			}
    			gpNTGLAPI->ntglEnd();
    #endif	//use nt vertex array
    		}
    		NT_GL(glPopMatrix())
    	}
    }
    Last edited by BobMcGee123; 07-30-2006 at 07:08 PM.
    I'm not immature, I'm refined in the opposite direction.

  2. #2
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Hey bob, lets talk about this in depth, I finally got my computer set up at work and now I have ALOT of spare time for programming, I'd like to get a centralized renderer setup in my engine along with my scene graph, I think you can help me now .

    Perhaps you could help walk me through the steps of converting an MS3D file into a more uniform format, and then rendering it. I look forward to your response .
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  3. #3

    Join Date
    May 2005
    Posts
    1,041
    You are too late for this. I had tried to help you many times before. Had you replied like last year I could have helped you, but I don't really program anymore. You have the code and the resources, you can figure this out. I figured out how to do it by reading the post you started on OpenGL.org, why can't you do the same?
    Last edited by BobMcGee123; 08-22-2007 at 05:14 PM.
    I'm not immature, I'm refined in the opposite direction.

  4. #4
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    Burn!

  5. #5

    Join Date
    May 2005
    Posts
    1,041
    No, I really wasn't trying to be a dick...I actually edited my post so it wouldn't seem like I was going out of my way to be offensive. I'm just personally sick/bored of programming and not really interested in investing huge amounts of time for no real gain (which includes spending hours explaining something to somebody). Sorries. Regardless, all of the code is still there. Good luck.
    Last edited by BobMcGee123; 08-22-2007 at 05:32 PM.
    I'm not immature, I'm refined in the opposite direction.

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,586
    The gain for most of us is satisfaction.

  7. #7

    Join Date
    May 2005
    Posts
    1,041
    Granted, I'm also busier with school than I ever have been before in my life, e.g. I had to go on a training cruise for half of my summer to get sea time so I can get a coast guard license when I graduate, just to give an idea. So, school is a major factor. Shamino, if you can ask specific questions I can still try to answer it, but I really don't want to do a 'sit down' and explain it all for hours on end.
    Last edited by BobMcGee123; 08-23-2007 at 08:37 AM.
    I'm not immature, I'm refined in the opposite direction.

  8. #8
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Thats cool bob, whatev floats your boat. Honestly I had forgotten I ever posted anything on OpenGL.org, and if you say it's my post that helped you well thats cool, I'll search for it now .
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  9. #9

    Join Date
    May 2005
    Posts
    1,041
    As I stated above, if you generate a specific question I will do the best to answer it for you. Just realize the reality is that if you do not understand it, you are going to have to put a lot of effort into reading/thinking until you do understand it, and if you are undertaking this project seriously you will develop insightful questions when you are stuck and to which I can promptly provide an answer. Ultimately, if you understand the basic idea, the code will make sense, but reading the code won't likely make the basic idea make sense.

    EDIT:
    Ultimately, I've just manipulated the data so that the MS3D data is turned into a new format such that it can be used with a call to OpenGL's glDrawElements. Re-reading the definition of that function on msdn.microsoft.com would be a great place to start.
    Last edited by BobMcGee123; 08-25-2007 at 02:56 PM.
    I'm not immature, I'm refined in the opposite direction.

  10. #10
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    I've got it up and running now.

    All I need to do now is remove the MS3D code from my main project and move it over to a seperate console app for conversion. I also need to adjust the scene manager so that it uses the Renderer with the new code instead of having MS3D model files draw themselves.

    And then I'll finally have a centralized renderer!

    This is exciting because I can finally stop working on this renderer thing and work on something that will work more towards a finished product rather than background code. After I get this setup I want to add bump mapping and some simple lighting, and then create a utility to create scenes for me. Perhaps it would be possible to convert quake 3 maps into my own format for rendering.
    Last edited by Shamino; 08-30-2007 at 11:17 AM.
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  11. #11

    Join Date
    May 2005
    Posts
    1,041
    The quake3 format is essentially setup in that manner.

    Also, I sincerely hope that you did not just copy my code and that you actually understand how and why the code works.

    Again, I edited my code because I realized I would come across as being unnecessarily harsh. Just realize that you really need to understand how this works before trying to use it. And again, while I am not as into programming as I used to be I would still answer questions.
    Last edited by BobMcGee123; 08-30-2007 at 04:12 PM.
    I'm not immature, I'm refined in the opposite direction.

  12. #12
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Lol no Bob I didn't use your code at all to help me, I experimented with my own class built from the Opengl.org forum post I made. Understanding code has never been a hassle for me, its actually sitting down and writing code that is a pain. But since I'm at a desk job now full time I have alot of spare time to write code in between support calls
    Last edited by Shamino; 08-31-2007 at 08:15 AM.
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  13. #13

    Join Date
    May 2005
    Posts
    1,041
    Fair enough then. Good luck.
    I'm not immature, I'm refined in the opposite direction.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. rand() implementation
    By habert79 in forum C Programming
    Replies: 4
    Last Post: 02-07-2009, 12:18 PM
  2. Caught a problem MS3D structure setup.
    By Shamino in forum Game Programming
    Replies: 3
    Last Post: 03-25-2006, 05:03 PM
  3. Updating an outdated MS3D Model Loader...
    By Shamino in forum Game Programming
    Replies: 8
    Last Post: 12-12-2005, 11:44 PM
  4. implementation file
    By bejiz in forum C++ Programming
    Replies: 5
    Last Post: 11-28-2005, 12:59 AM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21