float CPerlinRenderer::Dot(float A[2] , float B1, float B2)
{
return A[0]*B1+A[1]*B2;
}
float CPerlinRenderer::Cubic(float A, float B, float t)
{
return A+(3-2*t)*t*t*(B-A);
}
void CPerlinRenderer::GeneratePerlin(int TexRes, int TableRes)
{
float x, y;
//These are arrays with (int numDimensions, int Dimension1Size, ...)
Table.Init(3, TableRes+1, TableRes+1, 2);
TexData.Init(3, TexRes, TexRes, 4);
srand((unsigned int)time(0));
for(x=0; x<Table.Dimension[0]; x++)
for(y=0; y<Table.Dimension[1]; y++)
{
Table[x][y](0)=(float)rand()/RAND_MAX*2-1;
Table[x][y](1)=(float)rand()/RAND_MAX*2-1;
}
for(x=0; x<Table.Dimension[0]; x+=(float)Table.Dimension[0]/TexData.Dimension[0])
{
for(y=0; y<Table.Dimension[1]; y+=(float)Table.Dimension[1]/TexData.Dimension[1])
{
int Points[4];
Points[0]=(int)x;
Points[1]=(int)y;
Points[2]=Points[0]+1;
Points[3]=Points[1]+1;
float Vect[4];
Vect[0]=x-Points[0];
Vect[1]=y-Points[1];
Vect[2]=x-Points[2];
Vect[3]=y-Points[3];
float Dots[4];
Dots[0]=Dot(Table[Points[0]][Points[1]].Array, Vect[0], Vect[1]);
Dots[1]=Dot(Table[Points[2]][Points[1]].Array, Vect[2], Vect[1]);
Dots[2]=Dot(Table[Points[0]][Points[3]].Array, Vect[0], Vect[3]);
Dots[3]=Dot(Table[Points[2]][Points[3]].Array, Vect[2], Vect[3]);
CArray<float>& Color=TexData[TexData.Dimension[0]/Table.Dimension[0]*x][TexData.Dimension[1]/Table.Dimension[1]*y];
float Clr=Cubic(Cubic(Dots[0], Dots[1], Vect[0]), Cubic(Dots[2], Dots[3], Vect[0]), Vect[1]);
if(Clr<0)
Clr=0;
if(Clr>1)
Clr=1;
//Gives me red if I set only this one
Color(0)=0;
//Gives me green if I set only this one
Color(1)=0;
//Problem 1: No Color at all, but it probably is because of the other problem
Color(2)=Clr;
Color(3)=1;
}
}
glBindTexture(GL_TEXTURE_2D, Texture);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
//Problem 2: The texture has the weird solid bands at the top of it, I don''t think the perlin
//genreateing code is the problem, because I''ve used it before with no problem. What am I doing wrong here?
glTexImage2D(GL_TEXTURE_2D, 0, 4, TexRes, TexRes, 0, GL_RGBA, GL_FLOAT, TexData.Array);
glBindTexture(GL_TEXTURE_2D, 0);
}
If anyone can help, it would be greatly appreciated.
Tex Gen Issues
I''m making a perlin noise generator here''s the code
[s] [/s]
I can see the fnords.
I can see the fnords.
Just to clarify, when I use .Array on my previously mentioned array classes, it''s just the address the array is stored in
[s] [/s]
I can see the fnords.
I can see the fnords.
June 21, 2003 01:45 PM
Guess most people dont really understand what you''re trying to do.. since we are not involved in this project from the start
State your problem more clearly. No one is going to read though your code and guess what your issue/problems are.
What I want to do is make an OGL texture that contains perlin noise. First I create a array of floats (Column, Row, RGBA) that I use to put the texture in when I calculate it (the two loops do that). Finally I need to take this array and convert it to an OGL texture. I do this using the last few lines of code, but for some reason when I display the resulting texture there is a large solid colored band at the top of the texture, also the blue color channel doesn't work.
If you want to know how perlin nose works exactly goto www.angelcode.com
[edited by - DudeMiester on June 21, 2003 4:44:08 PM]
If you want to know how perlin nose works exactly goto www.angelcode.com
[edited by - DudeMiester on June 21, 2003 4:44:08 PM]
[s] [/s]
I can see the fnords.
I can see the fnords.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement