Advertisement

Bitmap loading

Started by April 04, 2009 02:09 PM
8 comments, last by Caste 15 years, 6 months ago
I have been following along with the code for the particle system in lesson 19 on the site and it seems very useful. However I do not understand how to get the code to work for loading a texture. The code in there is rather outdated and I'm using Visual Studio 2008. I'm pretty new to C++ but have worked in C# so the pointers and handles that exist are kind of throwing me for a loop. I understand what it is trying to do due to the excellent documentation, but I still can't figure it out myself. For example AUX_RGBImageRec *LoadBMP(char *Filename){...} Is supposedly a function which checks to see if there is a bitmap it can load. However AUX_RGBImageRec is not an object type I've ever heard of... and to give it a pointer as a function name confuses me. Is there a more recent way to import textures into OpenGL? My teacher has not covered it yet as we are still on lighting. Thanks for the help!
AUX_RGBImageRec is part of the glaux library which is now obsolete and probably shouldn't be used.


Quote:
AUX_RGBImageRec *LoadBMP(char *Filename){...} Is supposedly a function which checks to see if there is a bitmap it can load. However AUX_RGBImageRec is not an object type I've ever heard of... and to give it a pointer as a function name confuses me.




You're not giving AUX_RGBImageRec a pointer as a function type, LoadBMP is returning a pointer of type AUX_RGBImageRec. In the indirection operator (*) position doesn't effect it's association (int *a; is the same as int* a;). LoadBMP creates the AUX_RGBImageRec structure in memory and assuming there are no errors, populates it with data from the BMP at the path you specified. LoadBMP then returns a pointer of type AUX_RGBImageRec which contains the location in memory where LoadBMP stored the bitmap data (which is in the format described by the AUX_RGBImageRec structure).

You may have more luck moving ahead to Lesson 33 and doing TGA texture loading. At least it avoids glaux and it can be adapted to loading BMPs as well.


You might also consider reading the OpenGL Red Book(which is available for free) instead of the NEHE tutorials.


Anyway I hope this helps. :)

[Edited by - prh99 on April 4, 2009 2:32:08 PM]
Patrick
Advertisement
Well, we have gone over in class how to read in our own textures and now I am trying to apply that to some what the program covers, right now it handles the eruption great as long as I keep it in an infinite loop which then gives me a stack overflow (due to myself being unsure as to when to garbage collect which is a whole other issue in itself).
So I'm trying to apply the texture to each particle once in my "initializeParticleSystem()" method however I have not been able to get it to work well. Some of my other class mates suggested that I try messing around with some of my texture blending calls as I'm trying to use color to augment the texture where as currently it is replacing the color (ie. the texture isn't visible, only a solid color) So I will mess around with it and let people know what I find.
After working on this for a couple of hours again it seems the more pressing issue is trying to find a way to tell my particle system to loop so that it keeps flowing. It seems I can't create a loop function to do this because I'm also looking to take in keyboard input and the only way I've been able to get the particle system to display is if I lock the display system in a loop. Once I hand off control to glutMainLoop() it seems it's over. I'm trying to create a more friendly version of the particle system that exists where I'm not calling anything outdated or using the windows API.

Essentially I have a main() like this

initParticleSys();
glutDisplayFunc( display ); //sets up a pair of axes and other stuff
glutReshapeFunc( reshape );
glutKeyboardFunc( keyboard ); //looks for keyboard input
while( erupt == true)
drawExplosion();
glutMainLoop();

Thing is I can never see my result because I can't get it to glutMainLoop(), and as soon as I do, I can't keep the particle system going...Anyone have any advice for me to try? I will be seeing my teacher tomorrow about this, and I'll let you know what he tells me.
Well it seems that you need some info on how GLUT works.

If you call glutMainLoop() it just executes your drawing callback (called display() ).
GLUT will not update itself unless you add a "glutPostRedisplay()" either at the end of the display() method or add an glutIdleFunc. This request for a redisplay causes a call of display(), and if you do this all the time you'll get what you want, being a real animation.

Another thing to note is that many simple GLUT apps do not enable double buffering which might cause some flickering. Look at glutInitWindow() or so where you might have GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE. If you find GLUT_SINGLE here, then you're on a single buffered system which is the setup which might not look as good as a double buffered one.
So change GLUT_SINGLE to GLUT_DOUBLE and add glutSwapBuffers() at the end of your display() method instead of glFlush()

Hope that helps for now [smile]
Thanks Caste, that seems to have done the trick. I'm going to spend some time now to try and get the textures to map onto the particle and react to color changes now. Currently whatever color I'm giving the textures is being drawn as a solid color and not reacting to any alpha values, it's most likely something in the way I set up my blending, I may have to try and set up GlTexEnv I'm not sure. But I have some nice values set which make the eruption kind of look like a fountain which is pretty neat.

I plan on making some user interaction perhaps by taking input through the console and parsing it or just using key press commands depending on how difficult it turns out to be. I'll let you know what I come up with.
Advertisement
Checking for key input is really simple with GLUT:
-register a callback function for glutKeyboardFunc()
-implement a method with the type void myKeyCallback(char key, int x, int y) wich gives you the key as a char (so for instance check for key == 'a') and the mouse position when you hit this key.

And please tell ous about your results or add a screenshot [wink]
The volcano is coming along very nicely. I had to present it in class today. I may have time to provide you guys with some pictures this weekend or even a video depending on how much time I get. Thanks for your support!
Sorry again for the delay. I have put up 5 pictures of my volcano for you guys to look at. It turned out really nice. The only thing I would want to end up changing is making the textures read in the black areas of the particle as an alpha value. Which is something that could be done pretty easily but I didn't get done in time for me to present it to the class. Here is my photobucket album if you guys wish to look at the pictures!

http://s7.photobucket.com/albums/y256/12345SparksterZ/
Looks cool! Adding blending would make it look way better though.

You'll have problems with blending if you don't sort your particles back to front and render without depth testing because otherwise a nearer particle (which should be transparent) hides the ones behind it if these are drawn afterwards.

http://www.opengl.org/wiki/Alpha_Blending

This topic is closed to new replies.

Advertisement