Textures in Screensaver
Okay, I created a screensaver roughly based off Nehe''s particle tutorial and then converted into the actual screensaver using the skeleton at www.cornflakezone.com. Everything is working perfectly EXCEPT the textures. Instead of the nifty 2D "spheres" I get the boxes where the texture should be. If anyone can hazard a guess to why this is happening I would be very thankful.
You need to have all the OpenGL settings setup right. If you dont the textures wont show.
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL);
glEnable(GL_LIGHT0); // Quick And Dirty Lighting (Assumes Light0 Is Set Up)
glEnable(GL_LIGHTING); // Enable Lighting
glEnable(GL_COLOR_MATERIAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
There is also some things that you need in the function were you load the texture but im using glut.h no glaux.h so its probly diffrent for me.
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL);
glEnable(GL_LIGHT0); // Quick And Dirty Lighting (Assumes Light0 Is Set Up)
glEnable(GL_LIGHTING); // Enable Lighting
glEnable(GL_COLOR_MATERIAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
There is also some things that you need in the function were you load the texture but im using glut.h no glaux.h so its probly diffrent for me.
--------------------------Nukemmsn: nukem996@hotmail.comaim: nukem996open source open mind
Well, I have all that already. I tried a couple different things to see if anything would change, but no such luck yet. My texture loading is the same as Nehe so that may be the problem since I am combining it with the code at www.cornflakezone.com. While I doubt it matters, one uses a void heading for the program initilization while the other uses int. I also tried putting the data folder with the texture in the windows folder but the particles are still just translucent squares... I have no clue why it is being so stubborn. Should I post the code online somewhere so you guys can take a peek at it? Again, any help would be great!
Oh wow, what a wierd coincidence, I just semi-finished a particle screensaver *grin*
I''ve got textures loading on mine e.t.c just fine if the data folder is with the exe, but I wanted to change that to load the texture straight out of the exe resource file.
If you post your code up I''ll fix the image code for you for loading from a data folder.... but to be honest, after that''s done you''ll just want to change it to loading from resources in exe...
It''s your call.
I''ve got textures loading on mine e.t.c just fine if the data folder is with the exe, but I wanted to change that to load the texture straight out of the exe resource file.
If you post your code up I''ll fix the image code for you for loading from a data folder.... but to be honest, after that''s done you''ll just want to change it to loading from resources in exe...
It''s your call.
"Build a man a fire, and he will be warm for a day. Set a man on fire, and he will have warmth for the rest of his life"
Oh yeah.. and if anyone can tell me how to call the bitmap from the resource file it''d be appreciated.
i.e instead of loading "Data/particle.bmp" I load ________ (fill the gap). and using IDB_BITMAP2 doesnt work, because IDB_BITMAP2 is registered as an Int, not a char to the filename.
i.e instead of loading "Data/particle.bmp" I load ________ (fill the gap). and using IDB_BITMAP2 doesnt work, because IDB_BITMAP2 is registered as an Int, not a char to the filename.
"Build a man a fire, and he will be warm for a day. Set a man on fire, and he will have warmth for the rest of his life"
quote:
Original post by JimmyZJr
the particles are still just translucent squares...
You haven''t described really well what your expected outcome is versus the actual outcome, but I''m guessing it''s a blending problem. You''re wanting to remove some background color, and have a solid color sphere, instead of a blended translucent square, is this correct?
Are your textures on black backgrounds? If so, try a blendfunc of (GL_SRC_ALPHA, GL_ONE). Or else, please describe (or better yet, take a screenshot!) the problem in a little more detail.
----------------Amusing quote deleted at request of owner
Well, I may as well get it in working order using the external files. The saver skeleton can be found on the site I mentioned before and I will just insert what I changed from the GL_saver.cpp.
Everyting else is exactly the same
// Requisite headers#include <windows.h>#include <stdio.h>#include <math.h>#include <gl\gl.h>#include <gl\glu.h>#include <gl\glaux.h>#include "gl_saver.h"#define MAX_PARTICLES 1000bool keys[256];bool active = true;bool fullscreen = true;bool rainbow = true;bool sp;bool rp;bool exploded=true;float slowdown = 2.0f;float xspeed;float yspeed;float zoom = -40.0f;float xpos=0.0f;float ypos=-5.0f;float explodeheight;GLuint loop;GLuint color;GLuint delay;GLuint texture[1];typedef struct{ bool active; float life; float fade; float r; float b; float g; float x; float y; float z; float xi; float yi; float zi; float xg; float yg; float zg;}particles;particles particle[MAX_PARTICLES];static GLfloat colors[12][3] = { {1.0f,0.5f,0.5f},{1.0f,0.75f,0.5f},{1.0f,1.0f,0.5f},{0.75f,1.0f,0.5f}, {0.5f,1.0f,0.5f},{0.5f,1.0f,0.75f},{0.5f,1.0f,1.0f},{0.5f,0.75f,1.0f}, {0.5f,0.5f,1.0f},{0.75f,0.5f,1.0f},{1.0f,0.5f,1.0f},{1.0f,0.5f,0.75f}};AUX_RGBImageRec *LoadBMP(char *Filename){ FILE *File=NULL; if(!Filename) { return NULL; } File=fopen(Filename, "r"); if(File) { fclose(File); return auxDIBImageLoad(Filename); } return NULL;}int LoadGLTextures() { int Status=FALSE; AUX_RGBImageRec *TextureImage[1]; memset(TextureImage,0,sizeof(void *)*1); if (TextureImage[0]=LoadBMP("Data/Particle.bmp")) { Status=TRUE; glGenTextures(1, &texture[0]); glBindTexture(GL_TEXTURE_2D, texture[0]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); } if (TextureImage[0]) { if (TextureImage[0]->data) { free(TextureImage[0]->data); } free(TextureImage[0]); } return Status; }////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Do any initialization of the rendering context here, such as// setting background colors, setting up lighting, or performing// preliminary calculations.void GLSetupRC(void *pData) { glShadeModel(GL_SMOOTH); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearDepth(1.0f); glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texture[0]); for(loop=0; loop<MAX_PARTICLES; loop++) { particle[loop].active=true; particle[loop].life=1.0f; particle[loop].fade=float(rand()%100)/1000.0f + 0.003f; particle[loop].xg=0.0f; particle[loop].yg=-0.8f; particle[loop].zg=0.0f; } }//////////////////////////////////////////////////////////////////// Shutdown the rendering contextvoid GLShutdownRC(void) { }////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Render the OpenGL Scene here. Called by the WM_PAINT message// handler.void GLRenderScene(void *pData){ glEnable(GL_TEXTURE_2D); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glBindTexture(GL_TEXTURE_2D, texture[0]); ypos+=rand()%10*0.01f; if(exploded=true) { explodeheight=rand()%30*0.1f+7.0f; exploded=false; } if(ypos>=explodeheight) { for(loop=0; loop<MAX_PARTICLES; loop++) { particle[loop].life=1.0f; particle[loop].y=ypos; particle[loop].r=particle[0].r; particle[loop].g=particle[0].g; particle[loop].b=particle[0].b; particle[loop].fade=float(rand()%100)/1000.0f + 0.003f; particle[loop].xi=float((rand()%50)-26.0f)*10.0f; particle[loop].yi=float((rand()%50)-25.0f)*10.0f; particle[loop].zi=float((rand()%50)-25.0f)*10.0f; particle[loop].xg=0.0f; particle[loop].yg=-0.8f; particle[loop].zg=0.0f; } ypos=rand()%10*0.1f; exploded=true; xpos=rand()%10*1.0f-rand()%10*1.0f; } for (loop=0;loop<MAX_PARTICLES;loop++) { if(particle[loop].active) { float x=particle[loop].x; float y=particle[loop].y; float z=particle[loop].z+zoom; glColor4f(particle[loop].r,particle[loop].g,particle[loop].b,particle[loop].life); glBegin(GL_TRIANGLE_STRIP); glTexCoord2d(1,1); glVertex3f(x+0.4f,y+0.4f,z); glTexCoord2d(0,1); glVertex3f(x-0.4f,y+0.4f,z); glTexCoord2d(1,0); glVertex3f(x+0.4f,y-0.4f,z); glTexCoord2d(0,0); glVertex3f(x-0.4f,y-0.4f,z); glEnd(); particle[loop].x+=particle[loop].xi/(slowdown*1000); particle[loop].y+=particle[loop].yi/(slowdown*1000); particle[loop].z+=particle[loop].zi/(slowdown*1000); particle[loop].xi+=particle[loop].xg; particle[loop].yi+=particle[loop].yg; particle[loop].zi+=particle[loop].zg; particle[loop].life-=particle[loop].fade; if (particle[loop].life < 0.0f) { particle[loop].life=1.0f; particle[loop].fade=float(rand()%100)/1000.0f+0.003f; particle[loop].x=xpos; particle[loop].y=ypos; particle[loop].z=0.0f; particle[loop].xi=xspeed+float((rand()%60)-32.0f); particle[loop].yi=yspeed+float((rand()%60)-30.0f); particle[loop].zi=float((rand()%60)-30.0f); particle[loop].r=colors[color][0]; particle[loop].g=colors[color][1]; particle[loop].b=colors[color][2]; } if(keys[VK_NUMPAD8] && (particle[loop].yg<1.5f)) particle[loop].yg+=0.01f; if(keys[VK_NUMPAD2] && (particle[loop].yg>-1.5f)) particle[loop].yg-=0.01f; if(keys[VK_NUMPAD6] && (particle[loop].xg<1.5f)) particle[loop].xg+=0.01f; if(keys[VK_NUMPAD4] && (particle[loop].xg>-1.5f)) particle[loop].xg-=0.01f; } }}
Everyting else is exactly the same
Doh, well I forgot to get rid of the numpad interaction... not quite needed for a screensaver

I wonder if JimmyZJr was referring to these boxes

That's what I get in windows 16bit mode on the magic box tutorial, it seems to be a limitation of my old 4MB Riva 128 gfx card. The next shot is in 32bit but man is it slow:

[edited by - sodsm live on May 22, 2002 10:19:01 PM]

That's what I get in windows 16bit mode on the magic box tutorial, it seems to be a limitation of my old 4MB Riva 128 gfx card. The next shot is in 32bit but man is it slow:

[edited by - sodsm live on May 22, 2002 10:19:01 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement