OpenGL Model and Texture loading
I'm working on a 3D FPS written in C using GLUT, and decided that my 2-cuboid gun in pink
and blue wasn't good enough.
How would I load models and or textures?
I have a OBJ exporting program, but I'd be willing to make my own format.
Same with textures, I'd rather PNG, but anything'll do.
PS. I looked at NeHe's tutorial, but I'm lost. It seems to be for windoze.

Thanks.
and blue wasn't good enough. How would I load models and or textures?

I have a OBJ exporting program, but I'd be willing to make my own format.
Same with textures, I'd rather PNG, but anything'll do.
PS. I looked at NeHe's tutorial, but I'm lost. It seems to be for windoze.


Thanks.
~ Bring a Pen ~
For model loading, you'll basically want to pick a format (obj is a fine first choice if you don't need animation right away), write a parser for it, store the parsed vertex/texCoord/normal/etc. data in some sort of internal structure, and submit it to GL when you want to draw it. No magic involved, really.
For image loading, there are a number of options. Personally, I'm partial to libpng, but there's also stb_image, DevIL, and several others.
For image loading, there are a number of options. Personally, I'm partial to libpng, but there's also stb_image, DevIL, and several others.
Hmm... So, OBJ stores vertices as just one big polygon? I could maybe write a 'parser', but how would I tell GLUT to draw that? I mean, I couldn't draw a polygon...
And also, how do I access the actual .obj file?
I looked at libpng, but I don't understand. How does GLUT work with PNGs? Is there an easier way, like JPEG (kidding
) or TIFF???
And also, how do I access the actual .obj file? I looked at libpng, but I don't understand. How does GLUT work with PNGs? Is there an easier way, like JPEG (kidding
) or TIFF???
~ Bring a Pen ~
the most important things of obj are 'v <float> <float> <float>' and 'f <int> <int> <int>' each v is a point in space, each f references 3 points in space to make a triangle. There are a lot more things in obj which you might not bother to implement but with that much you could just tell opengl to draw all the triangles as given. (You might want to store normals too, or maybe just calculate them.. lots of choices)
Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote:Hmm... So, OBJ stores vertices as just one big polygon?As 'unknown' indicated, an .obj file stores (usually) multiple polygons, not one big polygon.
Quote:I could maybe write a 'parser', but how would I tell GLUT to draw that?How are you drawing your cubes?
As far as I'm aware, GLUT doesn't actually draw anything; it just provides a straightforward and portable means of setting up an OpenGL rendering context (OpenGL does the actual drawing).
To draw the model, you could use immediate mode, which is fast to get up and running, but not very efficient (and is also deprecated in the newest version of OpenGL). Or, you could use vertex arrays or VBOs.
Quote:And also, how do I access the actual .obj file?You would parse the .obj file, convert the data to arrays stored in memory, and then render directly from the arrays.
Quote:I looked at libpng, but I don't understand. How does GLUT work with PNGs?GLUT doesn't work with PNGs, or any other particular image format (again, AFAIK). You would load the images using one of the libraries mentioned previously, and then create texture objects from the images.
Quote:Is there an easier way, like JPEG (kidding ) or TIFF???How easy it is depends more on the library being used than on the image format. Any of the libraries mentioned previously should suffice (there are other options as well, such as SDL_image and FreeImage).
Quote:You would parse the .obj file, convert the data to arrays stored in memory, and then render directly from the arrays.
Yes, but how do I actually include the OBJ?
Code:
#include <obj.obj>Quote:'f <int> <int> <int>' each v is a point in space, each f references 3 points in space to make a triangle.
How do I specify the points?
Quote:GLUT doesn't work with PNGs, or any other particular image format (again, AFAIK). You would load the images using one of the libraries mentioned previously, and then create texture objects from the images.
How do I create texture objects? And How do I load the images?
~ Bring a Pen ~
Quote:Yes, but how do I actually include the OBJ?You can put the vertex data in a header file if you want. Most people prefer to use external files, which you just load with the usual file loading functions in whatever programming language or API you are using. In your case look at file handling in C - the fopen(), fclose() and fread() functions in particular.
Quote:How do I create texture objects? And how do I load the images?You can load images in many ways. Most people would use an existing library such as libpng, libjpeg, SDL_image or freeImage (I use the first two). You should look at some tutorials on creating OpenGL textures (or read Chapter 9 of the Red Book.
It looks like you might need to brush up on some basics before you get much further with your FPS.
Thanks, I'm looking into libpng and fopen().
Well, my FPS is just a project that keeps me interested while learning. Half learning, half playing, and constantly adding what I've learned. Yes?
Quote:It looks like you might need to brush up on some basics before you get much further with your FPS.
Well, my FPS is just a project that keeps me interested while learning. Half learning, half playing, and constantly adding what I've learned. Yes?
~ Bring a Pen ~
When you feel how depressingly
slowly you climb,
it's well to remember that
Things Take Time.
Piet Hein
slowly you climb,
it's well to remember that
Things Take Time.
Piet Hein
Sir, e^iπ + 1 = 0, hence God exists; reply!
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Texture Loading Cocoa/OpenGL | ultitech | 1 | 5,672 |
Jan 31, 2011 12:51 PM Last Post: mk12 |
|
| Loading Textures in OpenGL using libpng | Taxxodium | 9 | 11,896 |
Apr 4, 2006 09:21 PM Last Post: glMatt |
|

