Sign in to follow this  

Error With Lesson 31 From NeHe

This topic is 4093 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

Hi All: I am having the following error. Before the code was not compiling and I got the following error: d:\Profiles\r65136\Desktop\lesson31\MilkshapeModel.cpp(126): error C2664: 'std::basic_istream<_Elem,_Traits>::read' : cannot convert parameter 1 from 'byte *' to 'char *' with [ _Elem=char, _Traits=std::char_traits<char> ] So I converted pBuffer to (char *) pBuffer, I type casted. inputFile.read((char *)pBuffer, fileSize ); Then it compiled but now I am getting the following error when it runs. Lesson31.exe - Entry Point Not Found The procedure entry point SetPixelFormat could not be located in the dynamic link library OpenGL32.DLL. If anyone has any insight please help me!
/*
	MilkshapeModel.cpp

		Loads and renders a Milkshape3D model. 

	Author:	Brett Porter
	Email: brettporter@yahoo.com
	Website: http://www.geocities.com/brettporter/
	Copyright (C)2000, Brett Porter. All Rights Reserved.

	This file may be used only as long as this copyright notice remains intact.
*/

#include <windows.h>		// Header File For Windows
#include <gl\gl.h>			// Header File For The OpenGL32 Library

#include "MilkshapeModel.h"

#include "fstream"

MilkshapeModel::MilkshapeModel()
{
}

MilkshapeModel::~MilkshapeModel()
{
}

/* 
	MS3D STRUCTURES 
*/

// byte-align structures
#ifdef _MSC_VER
#	pragma pack( push, packing )
#	pragma pack( 1 )
#	define PACK_STRUCT
#elif defined( __GNUC__ )
#	define PACK_STRUCT	__attribute__((packed))
#else
#	error you must byte-align these structures with the appropriate compiler directives
#endif

typedef unsigned char byte;
typedef unsigned short word;

// File header
struct MS3DHeader
{
	char m_ID[10];
	int m_version;
} PACK_STRUCT;

// Vertex information
struct MS3DVertex
{
	byte m_flags;
	float m_vertex[3];
	char m_boneID;
	byte m_refCount;
} PACK_STRUCT;

// Triangle information
struct MS3DTriangle
{
	word m_flags;
	word m_vertexIndices[3];
	float m_vertexNormals[3][3];
	float m_s[3], m_t[3];
	byte m_smoothingGroup;
	byte m_groupIndex;
} PACK_STRUCT;

// Material information
struct MS3DMaterial
{
    char m_name[32];
    float m_ambient[4];
    float m_diffuse[4];
    float m_specular[4];
    float m_emissive[4];
    float m_shininess;	// 0.0f - 128.0f
    float m_transparency;	// 0.0f - 1.0f
    byte m_mode;	// 0, 1, 2 is unused now
    char m_texture[128];
    char m_alphamap[128];
} PACK_STRUCT;

//	Joint information
struct MS3DJoint
{
	byte m_flags;
	char m_name[32];
	char m_parentName[32];
	float m_rotation[3];
	float m_translation[3];
	word m_numRotationKeyframes;
	word m_numTranslationKeyframes;
} PACK_STRUCT;

// Keyframe data
struct MS3DKeyframe
{
	float m_time;
	float m_parameter[3];
} PACK_STRUCT;

// Default alignment
#ifdef _MSC_VER
#	pragma pack( pop, packing )
#endif

#undef PACK_STRUCT

bool MilkshapeModel::loadModelData( const char *filename )
{
	std::ifstream inputFile( filename, std::ios::in | std::ios::binary );
	if ( inputFile.fail())
		return false;	// "Couldn't open the model file."

	inputFile.seekg( 0, std::ios::end );
	long fileSize = inputFile.tellg();
	inputFile.seekg( 0, std::ios::beg );

	byte *pBuffer = new byte[fileSize];
	inputFile.read((char *)pBuffer, fileSize );
	inputFile.close();

	const byte *pPtr = pBuffer;
	MS3DHeader *pHeader = ( MS3DHeader* )pPtr;
	pPtr += sizeof( MS3DHeader );

	if ( strncmp( pHeader->m_ID, "MS3D000000", 10 ) != 0 )
		return false; // "Not a valid Milkshape3D model file."

	if ( pHeader->m_version < 3 || pHeader->m_version > 4 )
		return false; // "Unhandled file version. Only Milkshape3D Version 1.3 and 1.4 is supported." );

	int nVertices = *( word* )pPtr; 
	m_numVertices = nVertices;
	m_pVertices = new Vertex[nVertices];
	pPtr += sizeof( word );

	int i;
	for ( i = 0; i < nVertices; i++ )
	{
		MS3DVertex *pVertex = ( MS3DVertex* )pPtr;
		m_pVertices[i].m_boneID = pVertex->m_boneID;
		memcpy( m_pVertices[i].m_location, pVertex->m_vertex, sizeof( float )*3 );
		pPtr += sizeof( MS3DVertex );
	}

	int nTriangles = *( word* )pPtr;
	m_numTriangles = nTriangles;
	m_pTriangles = new Triangle[nTriangles];
	pPtr += sizeof( word );

	for ( i = 0; i < nTriangles; i++ )
	{
		MS3DTriangle *pTriangle = ( MS3DTriangle* )pPtr;
		int vertexIndices[3] = { pTriangle->m_vertexIndices[0], pTriangle->m_vertexIndices[1], pTriangle->m_vertexIndices[2] };
		float t[3] = { 1.0f-pTriangle->m_t[0], 1.0f-pTriangle->m_t[1], 1.0f-pTriangle->m_t[2] };
		memcpy( m_pTriangles[i].m_vertexNormals, pTriangle->m_vertexNormals, sizeof( float )*3*3 );
		memcpy( m_pTriangles[i].m_s, pTriangle->m_s, sizeof( float )*3 );
		memcpy( m_pTriangles[i].m_t, t, sizeof( float )*3 );
		memcpy( m_pTriangles[i].m_vertexIndices, vertexIndices, sizeof( int )*3 );
		pPtr += sizeof( MS3DTriangle );
	}

	int nGroups = *( word* )pPtr;
	m_numMeshes = nGroups;
	m_pMeshes = new Mesh[nGroups];
	pPtr += sizeof( word );
	for ( i = 0; i < nGroups; i++ )
	{
		pPtr += sizeof( byte );	// flags
		pPtr += 32;				// name

		word nTriangles = *( word* )pPtr;
		pPtr += sizeof( word );
		int *pTriangleIndices = new int[nTriangles];
		for ( int j = 0; j < nTriangles; j++ )
		{
			pTriangleIndices[j] = *( word* )pPtr;
			pPtr += sizeof( word );
		}

		char materialIndex = *( char* )pPtr;
		pPtr += sizeof( char );
	
		m_pMeshes[i].m_materialIndex = materialIndex;
		m_pMeshes[i].m_numTriangles = nTriangles;
		m_pMeshes[i].m_pTriangleIndices = pTriangleIndices;
	}

	int nMaterials = *( word* )pPtr;
	m_numMaterials = nMaterials;
	m_pMaterials = new Material[nMaterials];
	pPtr += sizeof( word );
	for ( i = 0; i < nMaterials; i++ )
	{
		MS3DMaterial *pMaterial = ( MS3DMaterial* )pPtr;
		memcpy( m_pMaterials[i].m_ambient, pMaterial->m_ambient, sizeof( float )*4 );
		memcpy( m_pMaterials[i].m_diffuse, pMaterial->m_diffuse, sizeof( float )*4 );
		memcpy( m_pMaterials[i].m_specular, pMaterial->m_specular, sizeof( float )*4 );
		memcpy( m_pMaterials[i].m_emissive, pMaterial->m_emissive, sizeof( float )*4 );
		m_pMaterials[i].m_shininess = pMaterial->m_shininess;
		m_pMaterials[i].m_pTextureFilename = new char[strlen( pMaterial->m_texture )+1];
		strcpy( m_pMaterials[i].m_pTextureFilename, pMaterial->m_texture );
		pPtr += sizeof( MS3DMaterial );
	}

	reloadTextures();

	delete[] pBuffer;

	return true;
}


Share this post


Link to post
Share on other sites
Hi yes I am using the built in compiler with Visual Studio.net 2003. Do I need to make any other changes? How can I get it to work? I just took the lesson 31 from the NEHe website, downloaded the one for the Visual Studio.net and then tried to run it, and have been unsuccessful, please help!

Share this post


Link to post
Share on other sites
I actually used the first link for lesson 31. http://nehe.gamedev.net/data/lessons/vc/lesson31.zip

Upgraded the vc6 proj to .net solution.
copy your source.
compile, ran, it worked.

Sorry I didn't go into it further but thats what I did and it worked, possibly a bug in the .net version. good luck.

Share this post


Link to post
Share on other sites
Hi:

Ok so I did that, and I get the following error. Did you have apstring.cpp and apstring.h? If so how did you get it?


c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\fstream.h(220): fatal error C1083: Cannot open include file: 'apstring.cpp': No such file or directory

Share this post


Link to post
Share on other sites
Ok so now I am getting the following errors:

d:\Profiles\r65136\Desktop\lesson31\MilkshapeModel.cpp(117): error C2079: 'inputFile' uses undefined class 'std::basic_ifstream<_Elem,_Traits>'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
d:\Profiles\r65136\Desktop\lesson31\MilkshapeModel.cpp(117): error C2078: too many initializers
d:\Profiles\r65136\Desktop\lesson31\MilkshapeModel.cpp(118): error C2228: left of '.fail' must have class/struct/union type
d:\Profiles\r65136\Desktop\lesson31\MilkshapeModel.cpp(121): error C2228: left of '.seekg' must have class/struct/union type
d:\Profiles\r65136\Desktop\lesson31\MilkshapeModel.cpp(122): error C2228: left of '.tellg' must have class/struct/union type
d:\Profiles\r65136\Desktop\lesson31\MilkshapeModel.cpp(123): error C2228: left of '.seekg' must have class/struct/union type
d:\Profiles\r65136\Desktop\lesson31\MilkshapeModel.cpp(126): error C2228: left of '.read' must have class/struct/union type
d:\Profiles\r65136\Desktop\lesson31\MilkshapeModel.cpp(127): error C2228: left of '.close' must have class/struct/union type

Any ideas?

Share this post


Link to post
Share on other sites
That was just a guess based on your compile error. I didn't get any of those errors. I'm running it at home on .net 2k5 and its the same, no errors. Sorry!

Try enabling c++ exceptions (the /EHsc option ). It is under properties -> C++ -> Code Generation -> enable c++ exceptions.

If thats already enabled, god bless you.

There must be a difference in the standard headers you are using and the ones I am using. Since the first error:

error C2079: 'inputFile' uses undefined class 'std::basic_ifstream<_Elem,_Traits>'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]

Describes ifstream is declared a prototype and used before defining.

Share this post


Link to post
Share on other sites
No such luck those were enabled. Any other ideas, I am desperate. Would it be any different that I am using Visual Studio.net 2003? Please help? Does anyone else have any ideas on how to bring a Milkshape 3D model into Visual Studio.net 2003.

Share this post


Link to post
Share on other sites

This topic is 4093 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this