Skip to main content
GameDev.net gamedev.net
🔒 Locked

linking other source files

Started by xCronus Apr 2, 2005 at 12:58 PM 6 replies 900+ views
Original Post
xCronus
xCronus
Hi. I wrote another .cpp file that contains a texture loading function for OpenGL code, so if I were to link it to another file that I was using, would I just use: #include as an include line? Also, can you declare a function to be of GLuint type so that it can return a texture handle?
RaptorZero
RaptorZero
I think you should declare the functions in the "texture loader.cpp" file in a header (texture loader.h) then include the header in "texture loader.cpp" and where you would use it's functions...

Quote:
Also, can you declare a function to be of GLuint type so that it can return a texture handle?


Yes... you could also pass a pointer to the handle in the function arguments

bool LoadTexture(..., GLuint *pHandle,...){    //...    glGenTextures(1, pHandle);    //...}
error C2065: 'signature' : undeclared identifier
Drew_Benton
Drew_Benton
Quote:
Original post by Anonymous Poster
from my understanding, dont use #include . If your using Dev-Cpp, all you have to do is include the .cpp without the main() in the project file you have the textureloaoder.h and main.cpp in. I thiink it also works in Visual-cpp, but I dont have it so I dont know.


AP and RaptorZero are correct. You never want to #include a .cpp file in either Dev or MSVC. If you had a .cpp file that contained the function, your best bet you be to declare a prototype somewhere else. IE:

Texture.h
#ifndef TEXTURE_#define TEXTURE_bool LoadTexture(..., GLuint *pHandle,...);#endif

Texture.cpp
bool LoadTexture(..., GLuint *pHandle,...){   ...}

Then when you need that function, you simply #include the header file in all of the files that you are needing it in, you must use include guards though, and all you need to do with the .cpp file is make sure it is a part of your workspace.

Quote:
Also, can you declare a function to be of GLuint type so that it can return a texture handle?


If you wanted to do that, you can also do something like this (NeHe's style on IPicture)
int BuildTexture(char *szPathName, GLuint &texid) // Load Image And Convert To A Texture...glGenTextures(1, &texid);// Create The Texture...

That is a little safer than passing by pointer [wink], but there is nothing wrong by using a pointer!
xCronus
xCronus
Thanks for the quick replies.

If I was going to convert the cpp file into a header, what would I need to do?
xCronus
xCronus
thanks for the burp
haha

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.