![]() This clearly isn't what you intended, but it works out nicely because you never release the memory in TempVertice, and it actually does contain all the vertices. In other words, you're constantly writing the TempVertice pointer into the Mesh.Vertice pointer. Is to copy the thing at the address of TempVertice into the thing at the address of Mesh.Vertice. What this line says: memcpy(&Mesh.Vertice, &TempVertice, sizeof (TempVertice)) Next it attempts to copy those 3 coordinates into the actual mesh, but it doesn't. It then reads 3 coordinates into memory pointed to by TempVertice. When it detects that the next thing in the file is a vertex, it allocates memory for 3 floats for each vertex. Let's just look at vertexes for the moment. It's not doing what you think it is, and I think you could greatly simplify it while making it more robust. There are several things wrong with your vertex and texture coordinate reading code. Printf("CModel::LoadTexture->Texture loaded %s %d\n", m_pFile, pTex) printf("Texture loaded %s Tex %d\n", pTexture.szFile, pTexture.pTex) //strncpy(pTexture.szFile, szFile, sizeof (pTexture.szFile) - 1) glTe圎nvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) ![]() gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, iWidth, iHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, BitMap) GlTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) GlTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) GlTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT) GlTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT) GlTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, iWidth, iHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, BitMap) Everything is in memory now, the file can be closed Read the actual data from the file into the buffer If (!DataPos) DataPos = 54 // The BMP header is done that way If (!Size) Size = iWidth * iHeight * 3 // 3 : one byte for each Red, Green and Blue component Some BMP files are misformatted, guess missing information Printf("CModel::LoadTexture->Not a correct BMP file\n") TempVertice = (float*)malloc(sizeof (float) * Mesh.TotalVertice * 3) įor (int i = 0 i Image could not be opened %s\n", m_pFile) Mesh.TextureID = LoadTexture(Mesh.Texture) If (!strncmp(szHeader, "mesh", 4)) continue įscanf(pFile, "%s", Mesh.Texture) If (!strncmp(szHeader, "BMAP", 4)) continue The TexCoord stores U and V value, and this is the result: GlDisableClientState(GL_TEXTURE_COORD_ARRAY) GlDrawElements(GL_TRIANGLES, * 3, GL_UNSIGNED_INT, ) GlEnableClientState(GL_TEXTURE_COORD_ARRAY) This is a piece of my render code glBindTexture(GL_TEXTURE_2D, ) Polygons with vertices outside of the viewing volume may be clipped to fit within the volume.I just move on from Immediate Mode and try Vertex Array method using glDrawElements and I got the texture is mess. All coordinates may then be divided by the w. In the context of OpenGL or Vulkan, the result of executing vertex processing shaders is considered to be in clip coordinates. Objects' coordinates are transformed via a projection transformation into clip coordinates, at which point it may be efficiently determined on an object-by-object basis which portions of the objects will be visible to the user. In OpenGL, clip coordinates are positioned in the pipeline just after view coordinates and just before normalized device coordinates (NDC). The clip coordinate system is a homogeneous coordinate system in the graphics pipeline that is used for clipping. Coordinate system used in computer graphics
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |