very simple and easy bmp loading for openGL

c_young
Unregistered
 
Post: #1
ive really just gotten into openGL but ive had some decent experience programing in other lanugages ( now using c++ ) so ive quickly been able to start my first openGL game. its a simple space shooter and so far everythings working and going great. ive been reading up on nehe, which has some really great tutorials and ive gotten everything. but textures ive been having some really big problems. because i am working in osx, obviously, many tutorials i find dont really give me any help at all. i have found a bunch of tutorials for osx but theyre all for use with cocoa wich is really confusing and i have no clue what to do with ( im using glut ). basically all my programs so far are really simple and stream line, they still get the job done and do everything, but theyre really simple and easy to understand. is there anyone who can explain, or show me to a tutorial for a really simple easy way to import bmp ( or another format ) for textures. much of the things ive seen so far are made up of like 4 header files and a seperate .cpp and all this random confusing code with pixel formats and i dont even know. could someone help me out? id like to be able to maybe have a max 1 headerfile to import them. and id liek to be able to make the header file myself so i actually understand the whole thing and im not just using someone elses code.

i understand what to do with the bmp once its loaded, how to make it into a texture and how to bind it. i just cant get the bmp loaded into my program.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #2
Not to discourage, but image loading isn't an easy task. Most file formats don't load nicely into a format that OpenGL can understand. There are a gazzilion ways to store image information, which is why the code you found had all sorts of code for handling pixel formats.

One of the easiest ways to load OpenGL friendly images is using libPNG. Given a couple of minutes, I could whip up a quick example...

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #3
uncompressed BMP is really easy to load and shove into OGL
find some specs on the file format

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #4
PNG loading example This code should load any valid PNG file into an RGBA texture.

The PNG loading code isn't so bad, but you have to handle a lot of special cases. It's pretty much straight out of the libPNG manual.

To make it work in your own code, you'll need to add the pngconf.h, png.h, libpng.a, and load_png.c files. You'll also need to add the function prototype for load_png to the top of your file. (like in main.c) Lastly, you'll need to open up the build settings for your application and add "-lz" to the "Other Linker Flags" setting.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
c_young
Unregistered
 
Post: #5
ok i havent had a chance to put this into my code yet, but i should be able to use it. the only question i have now is, how do you put 2 .c files into the same application? and i dont mean how do i do it, i mean how does the computer do it? i know just go file > add but how does the computer use 2 .c's in the same application?

*edit - ok so ive added that into my code, made some changed in the basics to fit in and and it runs and calls the function to load the png but then says theirs an error in load_png.c the file which you gave me. so im stuck again
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #6
When compiling, the compiler puts all the functions defined in all the .c files into your application. When the application starts, it uses the main() function as the entry point into the program.

Do you know about working directories? It's the directory that the program is run in. In XCode you can control the working directory of your program by going to the "Project" -> "Edit Active Executable" menu. If you use a relative path such as "monkey.png", it will look in the working directory for the file. So make sure that the file you want to load is in the working directory.

When you run a GLUT application from the finder, the working directory will be set to the Resources/ directory inside the app bundle.

I should also point out that the PNG loader doesn't do much for error handling. If there is an error, it will quit and tell you the line of the error, but that's about it. Though the only two errors that are likely to happen is that your file wasn't found, or it wasn't a PNG file.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
c_young
Unregistered
 
Post: #7
Skorche Wrote:When compiling, the compiler puts all the functions defined in all the .c files into your application. When the application starts, it uses the main() function as the entry point into the program.

so why not just put it in a header file instead of a .c? thats what i didnt get. and no the 2 errors are while compiling it says an improper conversion of variables. so it was something wrong with the files you gave me?
Quote this message in a reply
Moderator
Posts: 1,562
Joined: 2003.10
Post: #8
c_young Wrote:so why not just put it in a header file instead of a .c?
Let's say you have 200 .c files. After the initial compilation, only those which have been modified since the last compilation will need to be recompiled. This can speed up compile times dramatically, since you'll often only be changing a few of them per compile. However, if you have 1 .c file that includes 199 headers, the entire program will be recompiled every time.

That's only one example. There are plenty of other reasons for compartmentalizing your code into separate implementation files. I'll be writing a tutorial on it at some time in the near future...
Quote this message in a reply
c_young
Unregistered
 
Post: #9
email me a link to it when you make it, thatd be cool

wtswangx1@gmail.com
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #10
c_young Wrote:so why not just put it in a header file instead of a .c? thats what i didnt get. and no the 2 errors are while compiling it says an improper conversion of variables. so it was something wrong with the files you gave me?

It gives errors while compiling? You'll have to copy paste the them if you want better help, I have no idea what they would be.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL ES Loading images techy 4 3,989 Dec 24, 2009 02:01 PM
Last Post: techy
  Easy AudioServicesDisposeSystemSoundID question :D the_wandering_monster 0 3,108 Oct 20, 2009 02:18 AM
Last Post: the_wandering_monster
  Simple OpenGL ES problem soulstorm 3 4,362 May 14, 2009 03:53 PM
Last Post: AnotherJake
  Simple OpenGL 2d test - nothing displaying SaxMan 8 6,742 Jan 19, 2009 12:04 AM
Last Post: TythosEternal
  OpenGL ES - Drawing a simple cube help. MattCairns 7 12,776 Oct 10, 2008 05:26 PM
Last Post: Frogblast