Jump to content
  • Advertisement
Sign in to follow this  
ajm113

OpenGL In Motion Textures (Water, Clouds, etc)

This topic is 3825 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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;

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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();

Share this post


Link to post
Share on other sites
It seems that glActiveTexture is undeclared. I did some googleing, but just keep finding nothing useful.

Share this post


Link to post
Share on other sites
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 extensions
char* ext = glGetString(GL_EXTENSIONS);

// If you haven't GL_ARB_multitexture in your GPU extensions
if (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);
}
}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!