How to generate water in opengl
HI! Im kind of new to programming with opengl, but im very interested in learning it. While looking on the NeHe site i found an executable for a water wave project but there was no code http://nehe.gamedev.net/data/projects/project.asp?project=water If it is possible could i please get a copy of the code in C++ so i can see what is going on. thanks in advance!!
The "projects" do not come with source nor the source is avaliable to the best of my knowledge :(.
Quote:That's what I thought too, but:
Original post by Drew_Benton
The "projects" do not come with source nor the source is avaliable to the best of my knowledge :(.
Quote:
From project's page
Experiment with the code.
http://www.roboguy.net(WIP) - lisperati - SICP - Haskell - Python - OCaml - Lambda the Ultimate - Good Math, Bad Math - Wiki (not Wikipedia) - Pure - Term-Rewriting Functional Language
Quote:
Original post by Roboguy
Experiment with the code.
Probabally a mistype - for as long as I've been going to NeHe - I've seen it for about 3 years now, none of the projects have ever had source included on that side. i will check my old NeHe cd if I can find it, but I think that was just a typo in the page.
Edit: I checked my CD, they too do not even come with the source [sad]
Why can you not just texture some water unto lesson 11, thats what i did, works a treat.............unless you want something really snazzy of course
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=11
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=11
This is a great tutorial:
http://www.gamedev.net/reference/articles/article915.asp
It applies in 2d space but can easily be manipulated for 3d space.
Cheers,
- llvllatrix
http://www.gamedev.net/reference/articles/article915.asp
It applies in 2d space but can easily be manipulated for 3d space.
Cheers,
- llvllatrix
You could just draw a square, apply a texture, wait a few milliseconds, then replace it with another texture, and continue on. This procedure would be very similiar to how a film would generate movement.
Scroll down to the eighth project here
The example is in Delphi, but the theory of operation is very easy to understand.
Here is the code I derived from the Delphi source code in C++
Scroll down to the eighth project here
The example is in Delphi, but the theory of operation is very easy to understand.
Here is the code I derived from the Delphi source code in C++
/*==============================================================================Header Files and Global Defines==============================================================================*/#include "resource.h" //Header File for Resource IDs and Headers//Replace this header file as needed by your project./*==============================================================================Global Variables==============================================================================*///~~~~~External System Variables extern unsigned int texture[MAX_TEXTURE];//~~~~~Water typedef struct { float fade; float speed; float white_mask; float mask_alpha; } water_struct; water_struct water;/*==============================================================================FUNCTION PROTOTYPES==============================================================================*///Water Inilization Codebool xia_iniWater(float fade, float speed, float white);//Particle Generator Functionvoid xia_GenWater(int Start_Tex, int End_Tex, float size_x, float size_y, float speed, float red, float green, float blue, float alpha, float speed_mod);//Particle Drawinginline void xia_PersonalDrawParticle(float size_x, float size_y);/*==============================================================================Water Generator Code==============================================================================*///Water Inilization Codebool xia_iniWater(float fade, float speed, float white){ water.fade=fade; water.speed=speed; water.white_mask=white; water.mask_alpha=0.0; return TRUE;}//Water Generation Codevoid xia_GenWater(int Start_Tex, int End_Tex, float size_x, float size_y, float speed, float red, float green, float blue, float speed_mod){ static float counter=0.0; static int texture_count=Start_Tex; glColor4f(red, green, blue, water.fade); glBindTexture(GL_TEXTURE_2D, texture[texture_count]); xia_PersonalDrawParticle(size_x, size_y); if(counter > 0.2) { counter=0.0; texture_count++; if(texture_count == End_Tex) { texture_count=0; } } counter+=speed_mod*speed; water.fade+=speed_mod*water.speed;//White Mask glColor4f(1.0, 1.0, 1.0, water.mask_alpha); glDisable(GL_TEXTURE_2D); xia_PersonalDrawParticle(size_x, size_y); glEnable(GL_TEXTURE_2D); if(water.mask_alpha < water.white_mask) { water.mask_alpha+=speed_mod*water.speed*.2; }}//Particle Drawinginline void xia_PersonalDrawParticle(float size_x, float size_y){ glBegin(GL_TRIANGLE_FAN); glTexCoord2f(0.0,0.0); glVertex3f(0.0,0.0,0.0); glTexCoord2f(1.0,0.0); glVertex3f(size_x,0.0,0.0); glTexCoord2f(1.0,1.0); glVertex3f(size_x,size_y,0.0); glTexCoord2f(0.0,1.0); glVertex3f(0.0,size_y,0.0); glEnd();}
Thanks Alot guys for all of your help! Hey, does anyone have an idea on how to create a grid, say a square and randomly generate points to move on each line in the grid randomly. Say for example the grid is on a (x,y) plain. I want to be able to randomly generate point on x randomly as each line x moves in the y direction. If anyone could help me try to visualize this in c++ code i would greatly appretiate it. Thanks!!
What you want to do is use a seeded noise function, where if you increase the seed by 1 each frame it would generate the water using sins&cosins
----------------------------http://djoubert.co.uk
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement