PDA

View Full Version : Easy way to load and use a bmp, jpg, or tga file without windows progrmming know-how?



darkenreaper57
02-22-2004, 07:17 PM
I'm very new to openGL. I picked up a book and started reading, and im in the process of creating a game for my senior highschool project. Basically, i need to find out how to load a bmp or similar type if image to set as a background.

I know that you can load the bmp (or whatever) and then map it as a texture to a quad. Unfortunately, i don't know how to load it (or map it, for that matter, but i have a general idea)

I visited NeHe, and their tutorial was confusing with all the Windows API stuff...i know nothing about windows programing, only C++.

I tried some sample code others have posted, but when Microsoft Visual C++ 6 tries to compile, it give an error with the FILE* bmpfile; declaration. Windows.h is included in my program.

Anyway, if anyone could help me out and point me to a place that tells how to load a bmp WITHOUT all the windows api stuff, or supply me with some code, i would be very grateful, as i am running out of time.

chowe6685
02-22-2004, 09:49 PM
try using glfw
it provides a very easy interface to load targas
alternately you could include stdio.h and use the routines that others provided you with

marcus256
02-22-2004, 10:05 PM
At the GLFW site (http://glfw.sourceforge.net/) , you can find some OpenGL beginners tutorials (enough to get you started). Together with the comprehensive GLFW documentation and example programs, it should be a snap to get Targa texture loading and application running (hint: the glfwLoadTexture2D function loads a Targa from disk, and uploads it to texture memory, and even optionally builds all mipmap levels for you - in one function call).

darkenreaper57
02-23-2004, 07:11 AM
Ok, ill take a look at that. Thanks for everyone's help http://www.opengl.org/discussion_boards/ubb/smile.gif

darkenreaper57
02-23-2004, 07:31 AM
Hmm, one quick question...this CAN be used in conjunction with GLUT, right?

endash
02-23-2004, 09:33 AM
GLUT is just a set of helper functions for OpenGL, so yes, anything that works with OpenGL should work with OpenGL/GLUT.

chowe6685
02-23-2004, 09:37 AM
errr, I suppose you could, but GLFW is really a replacements for GLUT, they might work in tandem, but it would be really ugly and i don't recommend it. GLFW is really easy though, if you understand GLUT you could pick it up quickly

darkenreaper57
02-23-2004, 01:37 PM
It seems im having trouble getting GLFW to work. Here is what i have done do far:

Placed glfw.lib and glfwdll.lib in the .../lib directory of microsoft visual c++ 6.0.

Placed glfw.dll in /windows/syste32 (running xp pro)

Placed glfw.h in ...include\GL\glfw.h

I have included #include <gl/glfw.h> at the top

When i compile, i get an error:

main.obj : error LNK2001: unresolved external symbol _glfwLoadTexture2D
Debug/Ballistics.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

Any idea why? Thanks.

chowe6685
02-23-2004, 03:05 PM
you need to link with the library
ie
#pragma comment(lib, "glfw.lib")

dorbie
02-23-2004, 04:03 PM
Whoa, GLFW is a pretty much replacement for GLUT, you may be able to use parts of them together but that would probably be a bad way of going about things.

For loading images with GLUT you may want to use DevIL or something similar, or throw GLUT away and just use GLFW. As has been said you could probably pick it up easily.
http://openil.sourceforge.net/

Alternatively you could just visit NeHe and grab some simple texturing example code form there, and add it to what you have at the moment, it's not really that tricky.
http://nehe.gamedev.net/lesson.asp?index=02

marcus256
02-23-2004, 10:10 PM
Originally posted by darkenreaper57:
When i compile, i get an error:

main.obj : error LNK2001: unresolved external symbol _glfwLoadTexture2D
Debug/Ballistics.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

Any idea why? Thanks.

You have done everything correctly, except that you need to add glfw.lib to your projects list of link libraries (I always forget where that is in the VC++ IDE, since I always run command line, but it's where you have put opengl32.lib).

As mentioned earlier by other posts, GLFW is really a GLUT replacement (sorry for not making that clearer), but I figured that since you seem to be in the quite early stages of OpenGL development, it would not be too difficult to switch to another toolkit.

Theoretically, you could use the two together, but only in very special cases. GLFW texture loading requires a GLFW window, for instance, and will not work with a GLUT window. The threading, timing and joystick input functions can coexist with any environment though (even DirectX, if you wish). However, I do not recomment this kind of mixing.

Read the GLFW documentation, and see if it fits your needs. It's really easy to use, and in many ways more modern and better suited for certain tasks than GLUT. If you're not satisfied with GLFW, go for GLUT + DevIL.


[This message has been edited by marcus256 (edited 02-23-2004).]

darkenreaper57
02-24-2004, 06:53 AM
Ok, thank you for your help marcus, and everyone else. Because i am running out of time, i think ill stick with GLUT for now. I am able to load textures and map them to a quad, but it seems i am limited to a 128 by 128 bitmap. Is there any reason why this is (i know that the sizes need to be powers of two, or at least thats what i understand, but 256 by 256 hasnt worked yet).

This does not look great set as a background in a 800 by 600 window http://www.opengl.org/discussion_boards/ubb/frown.gif

I do not have the code here now as i am at school, but ill post it later on, and i will be very grateful if anyone can help me out.

colguin
03-04-2004, 10:05 PM
This is how you could load a 256x256 bitmap. To get the powers of 2 for any bitmap just use different sized arrays.

void load_bmp_256(char name[30], GLubyte image[256][256][3])
{
int i, j;
int stat;
char color[3];
FILE *fptr;

if ((fptr = fopen(name,"rb")) == NULL)
{
fprintf(stderr,"Unable to open BMP file.\n");
exit(-1);
}

fseek(fptr,54,SEEK_SET);

for (j=0;j<256;j++)
{
for (i=0;i<256;i++)
{
stat = fread(color, 1, 3, fptr);
image[i][j][0]=color[2];
image[i][j][1]=color[1];
image[i][j][2]=color[0];
}
}fclose(fptr);
}
void set_256_texture(GLubyte name[256][256][3])
{
glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, name);
}

MrShoe
03-05-2004, 12:25 AM
Try DevIL, I find that it is extremely good. Can be used with DirectX as well.