Jump to content
  • Advertisement
Sign in to follow this  

Error With Lesson 31 From NeHe

This topic is 4373 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!

		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"




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

typedef unsigned char byte;
typedef unsigned short word;

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

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

// 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;

// 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];

//	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;

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

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


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 );

	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.m_boneID = pVertex->m_boneID;
		memcpy( m_pVertices.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.m_vertexNormals, pTriangle->m_vertexNormals, sizeof( float )*3*3 );
		memcpy( m_pTriangles.m_s, pTriangle->m_s, sizeof( float )*3 );
		memcpy( m_pTriangles.m_t, t, sizeof( float )*3 );
		memcpy( m_pTriangles.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.m_materialIndex = materialIndex;
		m_pMeshes.m_numTriangles = nTriangles;
		m_pMeshes.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.m_ambient, pMaterial->m_ambient, sizeof( float )*4 );
		memcpy( m_pMaterials.m_diffuse, pMaterial->m_diffuse, sizeof( float )*4 );
		memcpy( m_pMaterials.m_specular, pMaterial->m_specular, sizeof( float )*4 );
		memcpy( m_pMaterials.m_emissive, pMaterial->m_emissive, sizeof( float )*4 );
		m_pMaterials.m_shininess = pMaterial->m_shininess;
		m_pMaterials.m_pTextureFilename = new char[strlen( pMaterial->m_texture )+1];
		strcpy( m_pMaterials.m_pTextureFilename, pMaterial->m_texture );
		pPtr += sizeof( MS3DMaterial );


	delete[] pBuffer;

	return true;

Share this post

Link to post
Share on other sites
I am using the built in compiler from Visual Studio.net 2003. What do I need to change from Lesson 31 in order for it to work with Visual Studio.

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

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
The original code calls for fstream.h - vc6 style.
Your code you posted doesn't, it uses fstream - no .h extension. Did you copy the source you posted and try that?

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>'
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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!