Problem loading texture

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
LEFRANCAIS
Posts: 28
Joined: Wed Oct 08, 2003 9:09 am
Location: Annecy - FRANCE

Problem loading texture

Post by LEFRANCAIS »

I want to load texture that is in my hard disq.
But Irrlicht said that he cant load the file.
I try to debug but i dont know why it doesnt work.
Here is my code:

Code: Select all

**********************************
main.h

#ifndef __MAIN_H__
#define __MAIN_H__
#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <commctrl.h>           
#include <stdio.h>
#include <irrlicht.h>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

#endif
**********************************

main.cpp
#pragma comment(lib, "irrlicht.lib")

#include <windows.h>
#include <commctrl.h> 
#include "main.h"


OPENFILENAME ofn;       // common dialog box structure
char szFile[260];       // buffer for filename
c8 IrrlichtImageFile[260];
HANDLE hf;              // file handle

IVideoDriver* driver = 0;
ICameraSceneNode* Camera = 0;
IParticleSystemSceneNode *Particle=0;
IParticleSystemSceneNode* ps = 0;
IParticleEmitter* em = 0;



int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{


	IrrlichtDevice *device =createDevice(video::EDT_DIRECTX9, core::dimension2d<s32>(800, 600), 32, false,false,false,0);

	driver = device->getVideoDriver();
	SExposedVideoData VideoData=driver->getExposedVideoData();
	HWND Hwnd = reinterpret_cast<HWND>(VideoData.OpenGLWin32.HWnd);

	strcpy(szFile,"particle.bmp");

	ZeroMemory(&ofn, sizeof(OPENFILENAME));
	ofn.lStructSize = sizeof(OPENFILENAME);
	ofn.hwndOwner = Hwnd;
	ofn.lpstrFile = szFile;
	ofn.nMaxFile = sizeof(szFile);
	ofn.lpstrFilter = "bmp\0*.bmp\0jpeg\0*.jpg\0";
	ofn.nFilterIndex = 1;
	ofn.lpstrFileTitle = NULL;
	ofn.nMaxFileTitle = 0;
	ofn.lpstrInitialDir = NULL;
	ofn.Flags = OFN_PATHMUSTEXIST;

	if (GetOpenFileName(&ofn)==TRUE) 
	{
		hf = CreateFile(ofn.lpstrFile, GENERIC_READ,
			0, (LPSECURITY_ATTRIBUTES) NULL,
			OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
			(HANDLE) NULL);
		strcpy(szFile,ofn.lpstrFile);
	}

	for (int f=0;f<(signed)strlen(szFile);f++)
	{
		IrrlichtImageFile[f]=szFile[f];
		if(szFile[f]=='\\') IrrlichtImageFile[f]='/';
	}
	strlwr(IrrlichtImageFile);

	scene::ISceneManager* smgr = device->getSceneManager();	
	Camera= smgr->addCameraSceneNode(0,vector3df(0,0,1000),vector3df(0,0,0),0);

	// create a particle system

	ps = smgr->addParticleSystemSceneNode(false);
	ps->setPosition(core::vector3df(0,0,0));
	ps->setScale(core::vector3df(10,10,10));

	ps->setParticleSize(core::dimension2d<f32>(20.0f, 10.0f));

	em = 	ps->createBoxEmitter(
			core::aabbox3d<f32>(-1,0,-1,1,1,1), 
			core::vector3df(0.001f,0.001f,0.001f),
			50,60, 
			video::SColor(0,100,100,100),   video::SColor(0,0,0,0),
			1000,1000,0);
	ps->setEmitter(em);
	em->drop();
	ps->setMaterialFlag(video::EMF_LIGHTING, false);
	ps->setMaterialTexture(0, driver->getTexture(IrrlichtImageFile));
	ps->setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);

	while(device->run())
	{
		driver->beginScene(true, true, 0);
		smgr->drawAll();
		driver->endScene();
	}

	em->drop();
	device->drop();	
	return 0;
}
**********************************
thx for your help
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Re: Problem loading texture

Post by Acki »

LEFRANCAIS wrote:for (int f=0;f<(signed)strlen(szFile);f++)
{
IrrlichtImageFile[f]=szFile[f];
if(szFile[f]=='\\') IrrlichtImageFile[f]='/';
}
Well, I think your problem is here...
strlen() returns the length of the string without the 0-termination !!!
So your IrrlichtImageFile string has no zero-termination !!!
You should try this:

Code: Select all

for (int f=0;f<(signed)strlen(szFile)+1;f++) 
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
LEFRANCAIS
Posts: 28
Joined: Wed Oct 08, 2003 9:09 am
Location: Annecy - FRANCE

Post by LEFRANCAIS »

Thx for your reply.

i try your code:

for (int f=0;f<(signed)strlen(szFile)+1;f++)

i open file that name is "couleur.bmp"
but i have always the same resultat:

Irrlicht message debug:
Could not open file of texture: g:/perso/essai/couleur.bmp
Could not load texture: g:/perso/essai/couleur.bmp

thx for your help.
LEFRANCAIS
Posts: 28
Joined: Wed Oct 08, 2003 9:09 am
Location: Annecy - FRANCE

Post by LEFRANCAIS »

Nobody? :(

i can't solve my problem.
help please.
POi

Post by POi »

The path should be backslash ( \ ) and not forwardslash ( / ). ????
POi

Post by POi »

Why do you change it ??
LEFRANCAIS
Posts: 28
Joined: Wed Oct 08, 2003 9:09 am
Location: Annecy - FRANCE

Post by LEFRANCAIS »

@ POi: Are you sure? I think the path should be "/"

I try your solution and irrlicht said:
Could not open file of texture: G:\PERSO\essai\couleur.bmp
Could not load texture: G:\PERSO\essai\couleur.bmp

Thx for reply :)
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

well, it doesn't matter if you use / or \
both are correct !!!!
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Post Reply