//here I generate the map, if I print in the loop to a file it gets correct in matlab, so uv-coords can't be wrong? void generateWorld::generateWorley(void) { double point[3]; double CellF[3]; double delta[3][3]; float ui, vi, min = 255.0f, max = 0.0f; unsigned long CellID; GLfloat h; double stoneScale = 64.0; for(int row = 0; row < NearTextureSize; row++ ) { for(int col = 0; col < NearTextureSize; col++ ) { point[0] = (double)row / (double)NearTextureSize * stoneScale; point[1] = (double)col / (double)NearTextureSize * stoneScale; point[2] = glfwGetTime(); ui = ((float)row)/((float)NearTextureSize)* stoneScale*2.0f; vi = ((float)col)/((float)NearTextureSize)* stoneScale*2.0f; Worley(point, 3, CellF, delta, &CellID); //h = 0.5+(CellF[1]-CellF[0]) * 0.4; h = (GLfloat)((2.0*CellF[2]-CellF[1]-CellF[0]) + 1.0*(0.5+inoise3f(ui, vi, 4.0f)) + 0.8*(0.5+inoise3f(ui*2.0f, vi*2.0f, 8.0f)) + 0.6*(0.5+inoise3f(ui*3.0f, vi*3.0f, 16.0f))); if(hmax) max=h; worleymap[row][col] = h; } } glGenTextures( 1, &worleyMap_tex_id ); glBindTexture( GL_TEXTURE_2D, worleyMap_tex_id ); glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); gluBuild2DMipmaps( GL_TEXTURE_2D, GL_LUMINANCE, NearTextureSize, NearTextureSize, GL_LUMINANCE, GL_FLOAT, worleymap ); } //and here I render it in a renderloop glPushMatrix(); glTranslatef(822,481,0); glColor3ub(255,255,255); //glScalef(200,200,200.0f); //glTexCoord2f(100.0f,100.0f); glBindTexture( GL_TEXTURE_2D, terrain.worleyMap_tex_id ); glBegin( GL_QUADS ); /* glTexCoord2f(0.0f, 0.2f); glVertex2i(0,0); glTexCoord2f(0.0f, 0.0f); glVertex2i(0,64); glTexCoord2f(0.4f, 0.0f); glVertex2i(128,64); glTexCoord2f(0.4f, 0.2f); glVertex2i(128,0); */ glTexCoord2f(0, 0.01f); glVertex2i(0,0); glTexCoord2f(0, 0); glVertex2i(0,64); glTexCoord2f(0.02f, 0); glVertex2i(128,64); glTexCoord2f(0.02f, 0.01f); glVertex2i(128,0); glEnd(); glPopMatrix();