8 Replies - 3655 Views - Last Post: 04 June 2012 - 03:08 PM Rate Topic: -----

#1 zehawk  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 213
  • Joined: 23-February 12

OpenGL Texture Mapping With Code::Blocks

Posted 04 June 2012 - 01:19 PM

Ok, heres a question I hope at least someone can help me with, I'm using Code::Blocks for OpenGL developement, and I'm at the point where I need to use texture mapping to draw surfaces with textures (Duh, thats what texture mapping is!:P) Anyways, I don't know how to get the resources(the textures) to compile with the actual program, and I don't know if Code::Blocks even has that functionality. Can i make a resource folder that will compile with the rest of the program? Or do i have to have a resource file outside of the executable and get the textures from there. Lastly, if the latter is my option, then will i have to have absolute paths, or can C++ use relative paths to do what i need? Any tutorials that use CODE::BLOCKS to do this will be helpful.

Reasons why I don't want Visual C++:
Regular Standard C++ code doesn't run correctly
Slower than Code Blocks
Forced to use Microsoft Compiler which wont let me use standard libraries and such
Linking with OpenGL is tougher than Code::Blocks!

Is This A Good Question/Topic? 0
  • +

Replies To: OpenGL Texture Mapping With Code::Blocks

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5921
  • View blog
  • Posts: 20,243
  • Joined: 05-May 12

Re: OpenGL Texture Mapping With Code::Blocks

Posted 04 June 2012 - 02:03 PM

Everything you need to know about resource files is here: http://msdn.microsof...9(v=vs.85).aspx

Basically, you'll need to make a .RC file that contains resource ids, resource types, and the filenames of the resources. You then pass that file to rc.exe which will generate a .RES file. You then pass that .RES file to your linker along with your object files, libraries, and main icon.

If the MSDN text is too dense reading, pick up a copy of Petzold's Programming Windows and it explains .RC files. Additionally, it is not dependent on Visual Studio as it is down to the basics building Windows programs using command line tools and makefiles.

Anyway, as an aside, do even really need your textures embedded as resources? I believe that the OpenGL API is agnostic about how the data is stored as long as you eventually call the API with an in memory copy of the texture. So it's your choice to have the texture embedded as resources or free floating files. If as free floating files, all the C/C++ APIs assume the current working directory if you don't provide a relative or explicit path.
Was This Post Helpful? 1
  • +
  • -

#3 zehawk  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 213
  • Joined: 23-February 12

Re: OpenGL Texture Mapping With Code::Blocks

Posted 04 June 2012 - 02:11 PM

Hey Skydiver, i plussed that because that was a great response, not some 'google it' that a lot of others do. I dont have to have it in the executable, im just worried about portability, i want to not neccessarily sell my games, but a portable version would be nice(portable as in the same os, but other computers of the same os can download it). Im thinking if i go the route of the images in their own folder, i will have to deal with createing an installer, and im really just a newbie learning this stuff, im only a teen and want to learn opengl. Ive done great up until texture mapping, and im clueless how to even begin. Resources.rc seems good, but linking is a little beyond me right now, i think ill go with the installer and file system method. If you can help me find a link, thatd be great, and yes, i googled this stuff already.
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5921
  • View blog
  • Posts: 20,243
  • Joined: 05-May 12

Re: OpenGL Texture Mapping With Code::Blocks

Posted 04 June 2012 - 02:28 PM

I've heard good things about "Advanced Installer", but I've never really used it: http://www.advancedinstaller.com/

I personally would advice learning to use WiX ( http://wix.codeplex.com/ ), but that is a steep learning curve that you probably don't want to climb right now. I know that drive of wanting to just work on the game, and not be bothered by the scaffolding. On the other hand, you can have instant job security since people hate putting together installers and if you can sell your skills as being able to write custom Windows installers instead of "one-size-fits-all" installers, you can have extra cash to spend on your game programming hobbies.
Was This Post Helpful? 1
  • +
  • -

#5 zehawk  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 213
  • Joined: 23-February 12

Re: OpenGL Texture Mapping With Code::Blocks

Posted 04 June 2012 - 02:35 PM

I'll definitly take a look, and being able to make an installer is definitly hard, but i think it does have some benefits. Ill try it out, and i think it might be a better idea than manageing resources and createing a bloated executable.

Thanks for the help!
Was This Post Helpful? 0
  • +
  • -

#6 zehawk  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 213
  • Joined: 23-February 12

Re: OpenGL Texture Mapping With Code::Blocks

Posted 04 June 2012 - 02:47 PM

Also, another alternative would be to package everything in a jar-esque fashion, however im really doubting c++ has an equivelant file formatting as Java's jar. Anyways, looking into installing right now.
Was This Post Helpful? 0
  • +
  • -

#7 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5921
  • View blog
  • Posts: 20,243
  • Joined: 05-May 12

Re: OpenGL Texture Mapping With Code::Blocks

Posted 04 June 2012 - 02:52 PM

Ah, but that is the magic of windows resources. Even if you have have a 60MB executable, if 50MB of that is resources, only the 10MB of your program is truly loaded into memory for execution. (Technically the entire executable is memory mapped, but for the sake of discussion, treat it as if the rest of the file isn't using "active" memory.) Resources are "brought into memory" when you call LoadResource().

If you write a good "resource manager" or "asset manager", you can let go of textures, sounds, and meshes that you aren't using right now be flushed out of memory. I think that the book Game Programming Gems 2 has a great article about writing your own resource manager, but don't quote me on which book. The books start to blur together after skimming through all of them.
Was This Post Helpful? 0
  • +
  • -

#8 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5921
  • View blog
  • Posts: 20,243
  • Joined: 05-May 12

Re: OpenGL Texture Mapping With Code::Blocks

Posted 04 June 2012 - 03:01 PM

View Postzehawk, on 04 June 2012 - 02:47 PM, said:

Also, another alternative would be to package everything in a jar-esque fashion, however im really doubting c++ has an equivelant file formatting as Java's jar. Anyways, looking into installing right now.


C++ natively doesn't, but you can use zlib ( http://zlib.net/ ) which you can link into your program. You can manage your "resource" file using the Windows Explorer, WinZip, 7-Zip, etc. I'm not sure about the veracity of this, but somebody once told me that Blizzard's MPQ file was originally just a ZIP file with some custom encryption.

Argh. Stupid mouse. Anyway, the point I was making was that if you didn't want a ton of loose files, and having to make a complex installer, you can have all the files be in the .zip file, and your installer will only need to install your program, the .zip file, and probably your .INI or .CONFIG file that you will come to the conclusion that you'll be needing. Your program will use zlib to open the .ZIP file that is installed along side with it, viola! you get access to your original files. No need to even unzip the .ZIP file.

This post has been edited by Skydiver: 04 June 2012 - 03:09 PM

Was This Post Helpful? 0
  • +
  • -

#9 zehawk  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 213
  • Joined: 23-February 12

Re: OpenGL Texture Mapping With Code::Blocks

Posted 04 June 2012 - 03:08 PM

Haha im downloading a opengl game programming book right now, i think ill need a book specifically for game programming to help me, truth is i guess im trying to run before walk. (Although, its just those damn textures!:P) I'll do what i can, and thanks for your help, ill check out those links you gave me, so i can either make an installer(Fun, fun) or use the resource handler thingie you shown me. And yes, you are correct, opengl doesnt require the resource.rc file, just the file location and then it will open up the bitmap etc. So perhaps resource.rc wont be that useful:p. Either way, if i wanted to be really daring, i could dynamically create textures in the code(which is both easy and hard, createing the texture is easy, creating a good texture... good luck!) Either way, now i have some options ill begin experimenting!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1