In Motion Textures (Water, Clouds, etc)

Started by
9 comments, last by MARS_999 16 years, 2 months ago
Hello, I created clouds in gimp using clouds filter in gimp. Then I created a alpha channel for it as well in my game in a tga formate to create a cloud look in my game. I am using NeHe's tga loader, and so far it's working. So how can I make my cloud texture move on a object to give that scrolling movement? Win32, C++, OpenGL, VS2005 [Edited by - ajm113 on February 10, 2008 2:30:33 PM]
Check out my open source code projects/libraries! My Homepage You may learn something.
Advertisement
You need to modify the texture coordinates, look into using the Texture Matrix, and then you can translate the coordinates as you wish.

e.g.
glMatrixMode(GL_TEXTURE);
glTranslatef();
glMatrixMode(GL_MODELVIEW);

HTH
Sorry for the late reply, but for some reason it seems that my textures just starting going into ugly pixels when it starts moving. This is some code.

float waterMove = 30.0f;				glPushMatrix( );				glMatrixMode(GL_TEXTURE);	glTranslatef(waterMove,waterMove,0.0f);	glMatrixMode(GL_MODELVIEW);				DrawFloor();		glPopMatrix( );	waterMove += 2.0f;	if(waterMove > 360){	waterMove -= 360;
Check out my open source code projects/libraries! My Homepage You may learn something.
I am at work, so I can't try this out at home, but try adding glLoadIdentity()

glMatrixMode(GL_TEXTURE);
glPushMatrix( );
glLoadIdentity();
glTranslatef(waterMove,waterMove,0.0f);
glPopMatrix();

also are you using shaders or FFP? Make sure the active texture unit that you want the water texture to move on is called before you go into glMatrixMode(GL_TEXTURE)

[Edited by - MARS_999 on February 23, 2008 6:59:46 PM]
I am not using any shaders, It seems too help a littel, but it still seems everything is still jumping around. Even my skybox is jumping around! Here is the new code:

	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		glMatrixMode(GL_MODELVIEW);		glLoadIdentity();		// use this function for opengl target camera	//gluLookAt(objCamera.mPos.x,  objCamera.mPos.y,  objCamera.mPos.z,		//		  objCamera.mView.x, objCamera.mView.y, objCamera.mView.z,		//		  objCamera.mUp.x,   objCamera.mUp.y,   objCamera.mUp.z);		// use this function for opengl target camera	gluLookAt(-100.0, 90.0, 30.0, 90.0, -60.0, -30.0, 0.0, 90.0, 0.0);	glPushMatrix( );	Draw_Skybox(0,0,0,RENDER_SIZE,RENDER_SIZE,RENDER_SIZE);	glPopMatrix( );			if(!Devmode){				glPushMatrix( );				glMatrixMode(GL_TEXTURE);	glLoadIdentity();	glTranslatef(waterMove,waterMove,0.0f);	glMatrixMode(GL_MODELVIEW);				DrawFloor();		glPopMatrix( );	waterMove += 2.0f;	if(waterMove > 360){	waterMove -= 360;	}[/souce]
Check out my open source code projects/libraries! My Homepage You may learn something.
Try this

DrawSky();

glBindTexture(GL_TEXTURE_2D, texID);
static float move = 0.0f;
move+=.001f;
glEnable(GL_TEXTURE_2D);
glActiveTexture(GL_TEXTURE0);

glMatrixMode(GL_TEXTURE);
glTranslatef(move, 0.0f, 0.0f);
glMatrixMode(GL_MODELVIEW);

DrawWater();
It seems that glActiveTexture is undeclared. I did some googleing, but just keep finding nothing useful.
Check out my open source code projects/libraries! My Homepage You may learn something.
It's part of GL_ARB_multitexture extension (now part of OpenGL core, but you need to test it as extension - that's OpenGL's backward compatibility) - declare at the beginning:
PFNGLACTIVETEXTUREPROC glActiveTexture = NULL;PFNGLMULTITEXCOORD2FPROC glMultiTexCoord2f = NULL;


Then test GL_ARB_multitexture extension (right after initialization of OpenGL):
//Get your graphics card extensionschar* ext = glGetString(GL_EXTENSIONS);// If you haven't GL_ARB_multitexture in your GPU extensionsif (strstr(ext, "GL_ARB_multitexture") == NULL){	// Message box	MessageBox(	NULL,"Extension was not found",				"ERROR",MB_OK|MB_ICONEXCLAMATION);}else{	// Find procedure address for glActiveTexture function	glActiveTexture = (PFNGLACTIVETEXTUREPROC)wglGetProcAddress("glActiveTexture");	// Find procedure address for glMultTexCoord2f function	glMultiTexCoord2f = (PFNGLMULTITEXCOORD2FPROC)wglGetProcAddress("glMultiTexCoord2f");	// If you haven't found procedures addresses	if(!glActiveTexture || !glMultiTexCoord2f )	{		// Message Box		MessageBox(NULL,"One or more extension functions were not				found",	"ERROR",MB_OK|MB_ICONEXCLAMATION);	}}

My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com

Do yourself a favor and grab GLEE or GLEW extension loader. No reason to code the function poniters yourself, unless you want control over what they are called... or just want to learn something else. You can drop the glActiveTexture() if you are only going to use texture unit 0. But I would get your code setup to do multi-texturing as you will want to use more than one texture unit eventually.
I'll try glew. Is their a difference with getting active set up with glee or glew?

Edit I tried setting up glew and glee, but it seems Visual Studio can't find the headers of both of them. I included the libs and placed the header files where glu.h and gl.h where and placed the bin with the platform SDK with the everything else that needs to go with what. I don't understand whats wrong. Do the files have too be imported into the project itself?
Check out my open source code projects/libraries! My Homepage You may learn something.

This topic is closed to new replies.

Advertisement