Hey everyone.
I have been following this tutorial http://www.mbsoftworks.sk/index.php?page=tutorials&series=1&tutorial=24 when trying to learn how to do a heightmap. I have managed to read in the vertex data but something is not correct.
When using the following grayscale image heightmap (in which i just display the vertex positions for now) Starts off very well but then it seems to duplicate the first part onto the end of the map (also seems like everything is a bit bunched up as the middle hole is not in the middle of the heightmap) Which results in it looking like this.
https://gyazo.com/cd642c41a92d4345bb4ca06dbc12ba1c
Atm I feel that the problem must be to do with the height of the pixel i read in but im not 100% sure. from what i have read up , the way i do it should be correct
Currently the grayscale image is a BMP 24 bitdepth 257*257. I use SDL to read in the image to calculate the vertex height
Below is the code i am currently using
getting the vertex points (like the tutorial i make sure the x and z are between -0.5 and 0.5 so it is centred)
SDL_Surface* img = SDL_LoadBMP(imagepath);
if (!img)
{
std::cout << "could not load the image";
return;
}
rows = img->h;
cols = img->w;
std::vector< std::vector<glm::vec3> > Tvetrices (rows,std::vector<glm::vec3>(cols));
std::vector< std::vector<glm::vec3> > TFinalNormals = std::vector< std::vector<glm::vec3> >(rows, std::vector<glm::vec3>(cols));
std::vector< std::vector<glm::vec2> > TUVs (rows , std::vector<glm::vec2>(cols));
float fTextureU = float(cols)*0.1f;
float fTextureV = float(rows)*0.1f;
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
float colscale = float(j) / float(cols - 1);
float rowscale = float(i) / float(rows - 1);
Uint32 pixle = ((Uint32*)img->pixels)[i * img->pitch/4 + j];
Uint8 r, g, b;
SDL_GetRGB(pixle, img->format, &r, &g, &b);
float hight = (float)r / 255.0;
Tvetrices[i][j] = glm::vec3((-0.5f + colscale) * 10, hight, (-0.5f + rowscale) * 10);
TUVs[i][j] = glm::vec2(fTextureU*colscale, fTextureV*rowscale);
}
}
vetrices = Tvetrices;
VBO set up (just want points for now so no intention for setup for tri's)
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
testver.push_back(vetrices[i][j]);
}
}
glBufferData(GL_ARRAY_BUFFER, testver.size() * sizeof(glm::vec3), &testver[0], GL_STATIC_DRAW);
draw call
glUseProgram(_program);
glBindVertexArray(_VAO);
glUniformMatrix4fv(_shaderModelMatLocation, 1, GL_FALSE, glm::value_ptr(_modelMatrix));
glUniformMatrix4fv(_shaderViewMatLocation, 1, GL_FALSE, glm::value_ptr(viewMatrix));
glUniformMatrix4fv(_shaderProjMatLocation, 1, GL_FALSE, glm::value_ptr(projMatrix));
glDrawArrays(GL_POINTS, 0, testver.size());
Any help will be greatly appreciated