About CreateUVmap
void CreateUVmap(IN long selected) { // 03-20-2019
MobjMesh* pMesh = >m_meshes[selected];
long index = pMesh->startIndex; // gnm_indexBuffer[pMesh->startIndex];
long vertsTotal = pMesh->triangleCount * 3;
long x = 0, y = 0, w = 0, h = 0, nW = 0, nH = 0, nIDtoClone = 0, nSpriteCount = 0, color = 0;
ZI_GetImageSizeFromControl(gT.hZoomCtrl, nW, nH);
HDC hIC = zDisplayDC();
HBITMAP hBitmap = zCreateDIBSection(hIC, nW, nH, 32);
HDC hDC = CreateCompatibleDC(hIC);
SelectObject(hDC, hBitmap);
DeleteDC(hIC);
//// Create a GDI32 transparent brush, to clear the bitmap background.
//HBRUSH hBrush = CreateSolidBrush(NULL);
//RECT r; SetRect(&r, 0, 0, nW, nH);
//FillRect(hDC, &r, hBrush);
//DeleteObject(hBrush);
POINT pt[3] = { 0 };
LONG_PTR graphics = 0, pen = 0, brush = 0;
GdipCreateFromHDC(hDC, graphics);
// Create a pen to draw with
GdipCreatePen1(ZD_ColorARGB(128, RGB(0,0,0)), 1.0f, UnitPixel, pen); // Do not use RGB(255,0,255), this is reserved for transparent GIF color.
//GdipCreateSolidFill(ZD_ColorARGB(64, RGB(225,225,225)), brush);
//WCHAR zAf[64] = { 0 };
long count = 0;
for (int j = 0; j < vertsTotal; j++, index++) {
MobjVertexT* vertex = >m_vertexBuffer[gnm_indexBuffer[index]];
pt[count].x = x = (long) ((nW - 1) * vertex->texCoord[0]);
pt[count].y = y = (long) ((nH - 1) * (1.0f - vertex->texCoord[1]));
count++;
if (count == 3) {
//GdipCreateSolidFill(ZD_ColorARGB(32, color), brush); color++; // Use a unique color for each triangle
//GdipFillPolygon2I(graphics, brush, pt[0], count);
//GdipDeleteBrush(brush);
GdipDrawPolygonI(graphics, pen, pt[0], count);
count = 0;
}
//StringCchPrintf(zAf, strSize(zAf), L"%d: %f, %f x = %2d, y = %2d", j+1, vertex->texCoord[0], vertex->texCoord[1], x, y);
//zTrace(zAf);
}
//GdipDeleteBrush(brush);
GdipDeletePen(pen);
GdipDeleteGraphics(graphics);
DeleteDC(hDC);
gT.MapID = IncrID();
ZD_DrawBitmapToCtrl(gT.hZoomCtrl, 0, 0, hBitmap, ZD_ColorARGB(255, 0), gT.MapID, ZS_VISIBLE);
ZD_SetObjectScroll(gT.MapID, TRUE);
SpriteArrayInit(gT.MapID, gT.MapFileName);
ZI_UpdateWindow(gT.hZoomCtrl, FALSE);
}
pMesh->triangleCount, reports the whole number of triangles in the mesh, but the UV's triangle count could be much smaller than that.
In the attached example, there are 440 triangles in the mesh, but only two in the corresponding UV flat projection.
What do you think is the best solution to draw only once the two triangles matching the UV's flat projection?