Original Post
Hello,
I am developing a fractal terrain generation based on an original 256x256 heightmap.
I need to use a texture to represent this heightmap, together with other gradients in each point, that is, 3 floats per 'texel'.
//////////////////////////////////////////////////////////////////////////////in the vertex shader, I am doing:
uniform sampler2D TexHeightMap;
vec4 GetVertCellParameters( uint i, uint j )
{
return texture( TexHeightMap, vec2( i, j ) ) * 2500.0f;
}
the * 2500.0f multiplication was used just to make sure the values are not somewhere between 0-1; in the final code,
the function will just return texture( TexHeightMap, vec2( i, j ) );
//////////////////////////////////////////////////////////////////////////////in the CPU, I am using:
void GLTexture::CreateHTExture( const void* pvBytes, unsigned int unW, unsigned int unH )
{
glEnable( GL_TEXTURE_2D );
glGenTextures( 1, &m_uglID );
glBindTexture( GL_TEXTURE_2D , m_uglID );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB32F, unW + 1, unH + 1, 0, GL_RGB, GL_FLOAT, pvBytes );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_LINEAR);
}
glEnable(GL_TEXTURE_2D );
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D , pTexture->GetID());
glUniform1i(m_ugl_HeightMapTexture, 0);
pTexture is of type GLTexture;
m_ugl_HeightMapTexture = glGetUniformLocation(m_uglProgram, "TexHeightMap");
for some reason, I am only getting zeros in the vertex shader ( when calling GetVertCellParameters ).
I checked the parameters pvBytes with memory view and they look fine.
I just need to get the float values, unmodified, just as I send them, in the vertex shader, and access them via texture as vec4.
Thank you.
I am developing a fractal terrain generation based on an original 256x256 heightmap.
I need to use a texture to represent this heightmap, together with other gradients in each point, that is, 3 floats per 'texel'.
//////////////////////////////////////////////////////////////////////////////in the vertex shader, I am doing:
uniform sampler2D TexHeightMap;
vec4 GetVertCellParameters( uint i, uint j )
{
return texture( TexHeightMap, vec2( i, j ) ) * 2500.0f;
}
the * 2500.0f multiplication was used just to make sure the values are not somewhere between 0-1; in the final code,
the function will just return texture( TexHeightMap, vec2( i, j ) );
//////////////////////////////////////////////////////////////////////////////in the CPU, I am using:
void GLTexture::CreateHTExture( const void* pvBytes, unsigned int unW, unsigned int unH )
{
glEnable( GL_TEXTURE_2D );
glGenTextures( 1, &m_uglID );
glBindTexture( GL_TEXTURE_2D , m_uglID );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB32F, unW + 1, unH + 1, 0, GL_RGB, GL_FLOAT, pvBytes );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_LINEAR);
}
glEnable(GL_TEXTURE_2D );
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D , pTexture->GetID());
glUniform1i(m_ugl_HeightMapTexture, 0);
pTexture is of type GLTexture;
m_ugl_HeightMapTexture = glGetUniformLocation(m_uglProgram, "TexHeightMap");
for some reason, I am only getting zeros in the vertex shader ( when calling GetVertCellParameters ).
I checked the parameters pvBytes with memory view and they look fine.
I just need to get the float values, unmodified, just as I send them, in the vertex shader, and access them via texture as vec4.
Thank you.