• Advertisement

Archived

This topic is now archived and is closed to further replies.

3ds file loader error!

This topic is 5786 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

could you guys help me with this i have been playing with the 3ds loader on gametutorials.com and with NeHe''s source code andd i got the file to show up but it gives me a error when i run it Assertion Failed so here is the code
  
#include <Main.h>
#include <3ds.h>

HDC			hDC=NULL;		// Private GDI Device Context

HGLRC		hRC=NULL;		// Permanent Rendering Context

HWND		hWnd=NULL;		// Holds Our Window Handle

HINSTANCE	hInstance;		// Holds The Instance Of The Application


bool	keys[256];			// Array Used For The Keyboard Routine

bool	active=TRUE;		// Window Active Flag Set To TRUE By Default

bool	fullscreen=TRUE;	// Fullscreen Flag Set To Fullscreen Mode By Default


#define FILE_NAME  "face.3ds"							// This is the 3D file we will load.


UINT g_Texture[MAX_TEXTURES] = {0};						// This holds the texture info, referenced by an ID


CLoad3DS g_Load3ds;										// This is 3DS class.  This should go in a good model class.

t3DModel g_3DModel;										// This holds the 3D Model info that we load in


int   g_ViewMode	  = GL_TRIANGLES;	

LRESULT	CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

void LoadScene(GLvoid)
{
	g_Load3ds.Import3DS(&g_3DModel, FILE_NAME);			// Load our .3DS file into our model structure


	// Depending on how many textures we found, load each one (Assuming .BMP)

	// If you want to load other files than bitmaps, you will need to adjust CreateTexture().

	// Below, we go through all of the materials and check if they have a texture map to load.

	// Otherwise, the material just holds the color information and we don''t need to load a texture.


	// Go through all the materials

	for(int i = 0; i < g_3DModel.numOfMaterials; i++)
	{
		// Check to see if there is a file name to load in this material

		if(strlen(g_3DModel.pMaterials[i].strFile) > 0)
		{
			// Use the name of the texture file to load the bitmap, with a texture ID (i).

			// We pass in our global texture array, the name of the texture, and an ID to reference it.	

			CreateTexture(g_Texture, g_3DModel.pMaterials[i].strFile, i);			
		}

		// Set the texture ID for this material

		g_3DModel.pMaterials[i].textureId = i;
	}

	// Here, we turn on a lighting and enable lighting.  We don''t need to

	// set anything else for lighting because we will just take the defaults.

	// We also want color, so we turn that on


	glEnable(GL_LIGHT0);								// Turn on a light with defaults set

	glEnable(GL_LIGHTING);								// Turn on lighting

	glEnable(GL_COLOR_MATERIAL);						// Allow colo

}

int DrawGLScene(GLvoid)									// Here''s Where We Do All The Drawing

{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer

	glLoadIdentity();

	LoadScene();

	gluLookAt(		0, 1.5f, 8,		0, 0.5f, 0,			0, 1, 0);

	for(int i = 0; i < g_3DModel.numOfObjects; i++)
	{
		// Make sure we have valid objects just in case. (size() is in the vector class)

		if(g_3DModel.pObject.size() <= 0) break;

		// Get the current object that we are displaying

		t3DObject *pObject = &g_3DModel.pObject[i];
			
		// Check to see if this object has a texture map, if so bind the texture to it.

		if(pObject->bHasTexture) {

			// Turn on texture mapping and turn off color

			glEnable(GL_TEXTURE_2D);

			// Reset the color to normal again

			glColor3ub(255, 255, 255);

			// Bind the texture map to the object by it''s materialID

			glBindTexture(GL_TEXTURE_2D, g_Texture[pObject->materialID]);
		} else {

			// Turn off texture mapping and turn on color

			glDisable(GL_TEXTURE_2D);

			// Reset the color to normal again

			glColor3ub(255, 255, 255);
		}

		// This determines if we are in wireframe or normal mode

		glBegin(g_ViewMode);					// Begin drawing with our selected mode (triangles or lines)


			// Go through all of the faces (polygons) of the object and draw them

			for(int j = 0; j < pObject->numOfFaces; j++)
			{
				// Go through each corner of the triangle and draw it.

				for(int whichVertex = 0; whichVertex < 3; whichVertex++)
				{
					// Get the index for each point of the face

					int index = pObject->pFaces[j].vertIndex[whichVertex];
			
					// Give OpenGL the normal for this vertex.

					glNormal3f(pObject->pNormals[ index ].x, pObject->pNormals[ index ].y, pObject->pNormals[ index ].z);
				
					// If the object has a texture associated with it, give it a texture coordinate.

					if(pObject->bHasTexture) {

						// Make sure there was a UVW map applied to the object or else it won''t have tex coords.

						if(pObject->pTexVerts) {
							glTexCoord2f(pObject->pTexVerts[ index ].x, pObject->pTexVerts[ index ].y);
						}
					} else {

						// Make sure there is a valid material/color assigned to this object.

						// You should always at least assign a material color to an object, 

						// but just in case we want to check the size of the material list.

						// if the size is at least one, and the material ID != -1,

						// then we have a valid material.

						if(g_3DModel.pMaterials.size() && pObject->materialID >= 0) 
						{
							// Get and set the color that the object is, since it must not have a texture

							BYTE *pColor = g_3DModel.pMaterials[pObject->materialID].color;

							// Assign the current color to this model

							glColor3ub(pColor[0], pColor[1], pColor[2]);
						}
					}

					// Pass in the current vertex of the object (Corner of current face)

					glVertex3f(pObject->pVerts[ index ].x, pObject->pVerts[ index ].y, pObject->pVerts[ index ].z);
				}
			}

		glEnd();								// End the drawing

	}


	return TRUE;										// Everything Went OK

}

int WINAPI WinMain(	HINSTANCE	hInstance,			// Instance

					HINSTANCE	hPrevInstance,		// Previous Instance

					LPSTR		lpCmdLine,			// Command Line Parameters

					int			nCmdShow)			// Window Show State

{
	MSG		msg;									// Windows Message Structure

	BOOL	done=FALSE;								// Bool Variable To Exit Loop


	// Ask The User Which Screen Mode They Prefer

	if (MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO)
	{
		fullscreen=FALSE;							// Windowed Mode

	}

	// Create Our OpenGL Window

	if (!CreateGLWindow("Raja''s 3ds game! i did it!",640,480,16,fullscreen))
	{
		return 0;									// Quit If Window Was Not Created

	}

	while(!done)									// Loop That Runs While done=FALSE

	{
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))	// Is There A Message Waiting?

		{
			if (msg.message==WM_QUIT)				// Have We Received A Quit Message?

			{
				done=TRUE;
			}
			else									// If Not, Deal With Window Messages

			{
				TranslateMessage(&msg);				// Translate The Message

				DispatchMessage(&msg);				// Dispatch The Message

			}
		}
		else										// If There Are No Messages

		{
			// Draw The Scene.  Watch For ESC Key And Quit Messages From DrawGLScene()

			if (active)								// Program Active?

			{
				if (keys[VK_ESCAPE])				// Was ESC Pressed?

				{
					done=TRUE;
					
					for(int i = 0; i < g_3DModel.numOfObjects; i++)
					{
						delete [] g_3DModel.pObject[i].pFaces;
						delete [] g_3DModel.pObject[i].pNormals;
						delete [] g_3DModel.pObject[i].pVerts;
						delete [] g_3DModel.pObject[i].pTexVerts;
					}
				}
				else								// Not Time To Quit, Update Screen

				{
					DrawGLScene();					// Draw The Scene

					SwapBuffers(hDC);				// Swap Buffers (Double Buffering)

				}
			}

			if (keys[VK_F1])						// Is F1 Being Pressed?

			{
				keys[VK_F1]=FALSE;					// If So Make Key FALSE

				KillGLWindow();						// Kill Our Current Window

				fullscreen=!fullscreen;				// Toggle Fullscreen / Windowed Mode

				// Recreate Our OpenGL Window

				if (!CreateGLWindow("Raja''s 3ds game! i did it!",640,480,16,fullscreen))
				{
					return 0;						// Quit If Window Was Not Created

				}
			}
		}
	}

	// Shutdown

	KillGLWindow();									// Kill The Window

	return (msg.wParam);							// Exit The Program

}
[source/]

thanks

Please Reply


  
Sir Darkan Fireblade

Share this post


Link to post
Share on other sites
Advertisement
int DrawGLScene(GLvoid) // Here''s Where We Do All The Drawing{ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer glLoadIdentity(); LoadScene();

you LoadScene more than once. do it once initialize.

Bobby

Share this post


Link to post
Share on other sites

  • Advertisement