Jump to content

View more

Image of the Day

The night is still, but the invasion brings chaos. #screenshotsaturday #hanako #indiegame #gameart #ue4 #samurai https://t.co/cgILXuokoS
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

Loading TGA - problems

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 kennez   Members   


Posted 26 February 2013 - 09:57 AM

Hi all,


First post here, so please be gentle with me. I'm sure I'm doing something really stupid, but I can't for the life of me figure it out!


I'm following this tutorial, http://www.rastertek.com/gl40tut05.html , and I'm having major problems - I cannot get the targa file texture to display at all. I've tried copying and pasting the code direct from the website into my project, but to no avail.


The relevant function is from the file graphicsclass.cpp, and the function is Initialize()


bool GraphicsClass::Initialize(OpenGLClass* OpenGL, HWND hwnd)
	bool result;

	// Store a pointer to the OpenGL class object.
	m_OpenGL = OpenGL;

	// Create the camera object.
	m_Camera = new CameraClass;
		return false;

	// Set the initial position of the camera.
	m_Camera->SetPosition(0.0f, 0.0f, -10.0f);

	// Create the model object.
	m_Model = new ModelClass;
		return false;

	// Get the full path of current exe file.
	TCHAR FilePath[MAX_PATH] = { 0 };
	GetModuleFileName( 0, FilePath, MAX_PATH );

	// Strip the exe filename from path and get folder name.
	PathRemoveFileSpec( FilePath );    

	// Set the current working directory.
	SetCurrentDirectory( FilePath );

	MessageBox( hwnd, FilePath, L"Error", MB_OK );

	// Initialize the model object.
	result = m_Model->Initialize( m_OpenGL, "data/test.tga", 0, true );
	if( !result ) {
		MessageBox( hwnd, L"Could not initialize the model object.", L"Error", MB_OK );
		return false;
	// Create the texture shader object.
	m_TextureShader = new TextureShaderClass;
		return false;

	// Initialize the texture shader object.
	result = m_TextureShader->Initialize(m_OpenGL, hwnd);
		MessageBox(hwnd, L"Could not initialize the texture shader object.", L"Error", MB_OK);
		return false;

	return true;

I keep hitting the error "Could not initialize the model object."


I've even gone through the other classes, copying and pasting them directly, but it still doesn't work. Any ideas?




Edited by kennez, 26 February 2013 - 10:05 AM.

#2 gfxgangsta   Members   


Posted 26 February 2013 - 11:05 AM

I keep hitting the error "Could not initialize the model object."


Have you tried stepping through the code with a debugger? What happens inside ModelClass::Initialize(...) that would make it return an invalid value? Can you post the code for ModelClass::Initialize(...) ?

#3 blueshogun96   Members   


Posted 27 February 2013 - 07:22 AM

If you go blindly copying and pasting code from random sources, then they are not guaranteed to work.  I highly recommend understanding how the code works before actually throwing it in your project.  It will save you much hassle.  You sound like you are very new to OpenGL (please correct me if I'm wrong).  If that's true, I strongly believe you are better off writing your own code to get a good understanding of what is going on.  You cannot rely on someone else's code all the time, and it's best to learn to walk on your own two feet at some point, even if you have to crawl first.


Now, I'm assuming that you're using Microsoft Visual Studio C++ as your compiler/IDE, right?  My recommendation to you is to insert a breakpoint before your call to m_Model->Initialize().  Start debugging, then when your breakpoint is hit, step into that function and follow it until you find out what's causing it to fail.  If you don't know how to use breakpoints, or don't know what a breakpoint is, read this: http://msdn.microsoft.com/en-us/library/ktf38f66(v=vs.71).aspx


Lastly, I don't mean to sound like a douchebag, but did you even read the code you've copied and pasted?  I took a look at the tutorial page you linked to and I'm 99.9% sure that the problem is with your .tga file isn't found.  If you're launching your .exe from Visual Studio, then you might need to change your working directory in the project settings.  And changing the directory with SetCurrentDirectory doesn't look necessary to me.  Reading from the wrong directory is likely your problem.


This is my advice to you.  Maybe I'm wrong, but you seem rather new to C++, Win32 programming and Visual Studio .net.  If this is true, please tell us so we can point you in the right direction so you can learn more!



Follow Shogun3D on the official website: http://shogun3d.net

Posted Image Posted Image Posted Image Posted Image

"Yo mama so fat, she can't be frustum culled." - yoshi_lol

"One objection to a “critique of C#” would be that you can’t talk about C# without talking about the whole “.Net experience”. However, one can approach the topic of Hitler without a complete discussion of Nationalist Socialism, so I feel justified." - Steve White.

#4 __SKYe   Members   


Posted 27 February 2013 - 12:12 PM

Looking at the Initialize method on that website, there are two ways that the method could fail.

Either failing to create the vertex/index buffer objects, which i don't think there's any problem with, or by failing to load the TGA image.


You could check the return value between those two function calls, to see which is causing the error.

Also, as Shogun said, did you make sure that the files you're trying to load exist in the correct folder (the TGA file, and perhaps also the shader files)?

Edited by __SKYe, 27 February 2013 - 12:12 PM.

#5 Ectara   Members   


Posted 27 February 2013 - 08:53 PM

I know it is kind of irrelevant, but those conditionals that check whether or not a pointer is null after you assigned a new'ed pointer to it won't ever get called. If it fails to allocate memory, it will throw an exception, which will stop executing the function and work its way up the call stack. I doubt that this is what you intended. The only way to get that behavior is to use new(std::nothrow), but first, learning about the language is more important.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.