UVRECT convertUV(UVRECT input, int tilesetId, int tilesetWidth, int tilesetHeight) { UVRECT output; output.x1 = (1.0f / (float)tilesetWidth) * input.x1; output.x2 = (1.0f / (float)tilesetWidth) * input.x2; output.y1 = (1.0f / (float)tilesetHeight) * input.y2; output.y2 = (1.0f / (float)tilesetHeight) * input.y1; return(output); }
void renderTile(int x, int y, float z, int tilesetid, UVRECT uv_rect) { renderTile(x, y, z, tilesetid, uv_rect, false); }
void renderTile(int x, int y, float z, int tilesetid, UVRECT uv_rect, bool whole) { //tilesetid: 0 - A1, 1 - A2...8 - E //step 1: bind appropriate texture int tilesetWidth = 0; int tilesetHeight = 0; switch (tilesetid) { case 0: //A1 if (tilesetA1 == 0) { return; } bindTexture(tilesetA1); tilesetWidth = tilesetA1_w; tilesetHeight = tilesetA1_h; break; case 1: //A2 if (tilesetA2 == 0) { return; } bindTexture(tilesetA2); tilesetWidth = tilesetA2_w; tilesetHeight = tilesetA2_h; break; case 2: //A3 if (tilesetA3 == 0) { return; } bindTexture(tilesetA3); tilesetWidth = tilesetA3_w; tilesetHeight = tilesetA3_h; break; case 3: //A4 if (tilesetA4 == 0) { return; } bindTexture(tilesetA4); tilesetWidth = tilesetA4_w; tilesetHeight = tilesetA4_h; break; case 4: //A5 if (tilesetA5 == 0) { return; } bindTexture(tilesetA5); tilesetWidth = tilesetA5_w; tilesetHeight = tilesetA5_h; break; case 5: //B if (tilesetB == 0) { return; } bindTexture(tilesetB); tilesetWidth = tilesetB_w; tilesetHeight = tilesetB_h; break; case 6: //C if (tilesetC == 0) { return; } bindTexture(tilesetC); tilesetWidth = tilesetC_w; tilesetHeight = tilesetC_h; break; case 7: //D if (tilesetD == 0) { return; } bindTexture(tilesetD); tilesetWidth = tilesetD_w; tilesetHeight = tilesetD_h; break; case 8: //E if (tilesetE == 0) { return; } bindTexture(tilesetE); tilesetWidth = tilesetE_w; tilesetHeight = tilesetE_h; break; } int drawx = x; int drawy = 0 - y; if (whole) { drawy -= 16; } //grab dimensions of the original src_rect before we convert it to uv int draww = (int)(uv_rect.x2 - uv_rect.x1); int drawh = (int)(uv_rect.y2 - uv_rect.y1); //we'll set color on a per-draw basis for now in case we want to get crafty later GL.Color4(1f, 1f, 1f, 1f); //process the uv rect from pixels to uv UVRECT tileuv = convertUV(uv_rect, tilesetid, tilesetWidth, tilesetHeight); GL.Enable(EnableCap.Texture2D); GL.Begin(BeginMode.Polygon); GL.TexCoord2(tileuv.x1, tileuv.y2); GL.Vertex3(drawx, drawy + drawh, z); // bottom left GL.TexCoord2(tileuv.x1, tileuv.y1); GL.Vertex3(drawx, drawy, z); // top left GL.TexCoord2(tileuv.x2, tileuv.y1); GL.Vertex3(drawx + draww, drawy, z); // top right GL.TexCoord2(tileuv.x2, tileuv.y2); GL.Vertex3(drawx + draww, drawy + drawh, z); // bottom right GL.End(); }
void renderTile(int x, int y, float z, int tilesetid, UVRECT uv_rect){ renderTile(x,y,z,tilesetid,uv_rect,false); }
void renderTile(int x, int y, float z, int tilesetid, UVRECT uv_rect, bool whole){ //tilesetid: 0 - A1, 1 - A2...8 - E //step 1: bind appropriate texture int tilesetWidth = 0; int tilesetHeight = 0; switch(tilesetid){ case 0: //A1 if (tilesetA1 == 0) return; bindTexture(tilesetA1); tilesetWidth = tilesetA1_w; tilesetHeight = tilesetA1_h; break; case 1: //A2 if (tilesetA2 == 0) return; bindTexture(tilesetA2); tilesetWidth = tilesetA2_w; tilesetHeight = tilesetA2_h; break; case 2: //A3 if (tilesetA3 == 0) return; bindTexture(tilesetA3); tilesetWidth = tilesetA3_w; tilesetHeight = tilesetA3_h; break; case 3: //A4 if (tilesetA4 == 0) return; bindTexture(tilesetA4); tilesetWidth = tilesetA4_w; tilesetHeight = tilesetA4_h; break; case 4: //A5 if (tilesetA5 == 0) return; bindTexture(tilesetA5); tilesetWidth = tilesetA5_w; tilesetHeight = tilesetA5_h; break; case 5: //B if (tilesetB == 0) return; bindTexture(tilesetB); tilesetWidth = tilesetB_w; tilesetHeight = tilesetB_h; break; case 6: //C if (tilesetC == 0) return; bindTexture(tilesetC); tilesetWidth = tilesetC_w; tilesetHeight = tilesetC_h; break; case 7: //D if (tilesetD == 0) return; bindTexture(tilesetD); tilesetWidth = tilesetD_w; tilesetHeight = tilesetD_h; break; case 8: //E if (tilesetE == 0) return; bindTexture(tilesetE); tilesetWidth = tilesetE_w; tilesetHeight = tilesetE_h; break; } int drawx = x; int drawy = 0 - y; if(whole) drawy -= 16; //grab dimensions of the original src_rect before we convert it to uv int draww = (int) (uv_rect.x2 - uv_rect.x1); int drawh = (int) (uv_rect.y2 - uv_rect.y1); //we'll set color on a per-draw basis for now in case we want to get crafty later GL.Color4(1f, 1f, 1f, 1f); //process the uv rect from pixels to uv UVRECT tileuv = convertUV(uv_rect, tilesetid, tilesetWidth, tilesetHeight); GL.Enable(EnableCap.Texture2D); GL.Begin(BeginMode.Polygon); GL.TexCoord2 (tileuv.x1, tileuv.y2); GL.Vertex3(drawx, drawy + drawh, z); // bottom left GL.TexCoord2 (tileuv.x1, tileuv.y1); GL.Vertex3(drawx, drawy, z); // top left GL.TexCoord2 (tileuv.x2, tileuv.y1); GL.Vertex3(drawx + draww, drawy, z); // top right GL.TexCoord2 (tileuv.x2, tileuv.y2); GL.Vertex3(drawx + draww, drawy + drawh, z); // bottom right GL.End(); }
UVRECT convertUV(UVRECT input, int tilesetId, int tilesetWidth, int tilesetHeight){ UVRECT output; output.x1 = (1.0f / (float) tilesetWidth) * input.x1; output.x2 = (1.0f / (float) tilesetWidth) * input.x2; output.y1 = (1.0f / (float) tilesetHeight) * input.y2; output.y2 = (1.0f / (float) tilesetHeight) * input.y1; return output; }