public ExtraTileInfo (LayMapTile tile, OGLTextureManager manager) { Parent = tile; TextureManager = manager; Texture = TextureManager.LoadTexture(EvilTools.GetExecutingPath(@"MapEditor\Tiles\" + tile.Id + ".png")); if (Texture == null) Texture = TextureManager.LoadTexture(EvilTools.GetExecutingPath(@"MapEditor\Tiles\unknown.png")); }
public static void DrawTexture(OGLTexture txt, Position2D texturePosition, Dimension2D textureSize, Position2D srcPosition, Position2D targetPosition, float Alpha) { Dimension2D tSize = new Dimension2D(targetPosition.X - srcPosition.X, targetPosition.Y - srcPosition.Y); DrawTexture(txt, texturePosition, textureSize, srcPosition, tSize, Alpha); }
public static void DrawTexture(OGLTexture txt, Position2D texturePosition, Dimension2D textureSize, Position2D targetPosition, Dimension2D targetSize, float Alpha) { /*if ((targetPosition.X < 0) || (targetPosition.X >= oGL.Width)) * return; * if ((targetPosition.Y < 0) || (targetPosition.Y >= oGL.Height)) * return; * if ((targetPosition.X + targetSize.Width < 0) || (targetPosition.X + targetSize.Width >= oGL.Width)) * return; * if ((targetPosition.Y + targetSize.Height < 0) || (targetPosition.Y + targetSize.Height >= oGL.Height)) * return;*/ glEnable2D(); glEnable(Gl.GL_ALPHA); OGLTools.glEnable(Gl.GL_TEXTURE_2D); Gl.glEnable(Gl.GL_BLEND); Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA); Gl.glColor4f(1.0f, 1.0f, 1.0f, Alpha); Gl.glPushMatrix(); Gl.glTranslated(targetPosition.X, targetPosition.Y, 0); if (m_CurrentTextureID != (int)txt.TextureId) { m_CurrentTextureID = (int)txt.TextureId; Gl.glBindTexture(Gl.GL_TEXTURE_2D, m_CurrentTextureID); } float x1, y1; Gl.glBegin(Gl.GL_QUADS); // Extract bottom left position //x1 = (1.0f / (float)txt.Size.Width * (float)texturePosition.X) - txt.Size.GetFloatingX(textureSize.Width - txt.Size.Width); //y1 = (1.0f / (float)txt.Size.Height * (float)texturePosition.Y) - txt.Size.GetFloatingY(textureSize.Width - txt.Size.Height); x1 = 1 / (float)txt.Size.Width * (float)texturePosition.X; y1 = 1 / (float)txt.Size.Height * (float)texturePosition.Y; Gl.glTexCoord2f(x1, y1 * -1); Gl.glVertex2i(0, 0); // Extract bottom right //x1 = (1.0f / (float)txt.Size.Width * (float)texturePosition.X) - txt.Size.GetFloatingX(textureSize.Width); //y1 = (1.0f / (float)txt.Size.Height * (float)texturePosition.Y) - txt.Size.GetFloatingY(textureSize.Height - txt.Size.Height); x1 = 1 / (float)txt.Size.Width * ((float)texturePosition.X + (float)textureSize.Width); y1 = 1 / (float)txt.Size.Height * (float)texturePosition.Y; Gl.glTexCoord2f(x1, y1 * -1); Gl.glVertex2i(targetSize.Width, 0); // Extract top right //x1 = (1.0f / (float)txt.Size.Width * (float)texturePosition.X) - txt.Size.GetFloatingX(textureSize.Width); //y1 = (1.0f / (float)txt.Size.Height * (float)texturePosition.Y) - txt.Size.GetFloatingY(textureSize.Height); x1 = 1 / (float)txt.Size.Width * ((float)texturePosition.X + (float)textureSize.Width); y1 = 1 / (float)txt.Size.Height * ((float)texturePosition.Y + (float)textureSize.Height); Gl.glTexCoord2f(x1, y1 * -1); Gl.glVertex2i(targetSize.Width, targetSize.Height); // Extract top left position //x1 = (1.0f / (float)txt.Size.Width * (float)texturePosition.X) - txt.Size.GetFloatingX(textureSize.Width - txt.Size.Width); //y1 = (1.0f / (float)txt.Size.Height * (float)texturePosition.Y) - txt.Size.GetFloatingY(textureSize.Height); x1 = 1 / (float)txt.Size.Width * (float)texturePosition.X; y1 = 1 / (float)txt.Size.Height * ((float)texturePosition.Y + (float)textureSize.Height); Gl.glTexCoord2f(x1, y1 * -1); Gl.glVertex2i(0, targetSize.Height + 0); Gl.glEnd(); // disable blending glDisable(Gl.GL_BLEND); Gl.glPopMatrix(); // Need to optimize this like glPopMatrix(sessionID); }
internal void Add(OGLTexture oGLTexture, string key) { Textures.Add(key, oGLTexture); }
public static void DrawTexture(OGLTexture txt, Position2D texturePosition, Dimension2D textureSize, Position2D targetPosition, Dimension2D targetSize, float Alpha) { /*if ((targetPosition.X < 0) || (targetPosition.X >= oGL.Width)) return; if ((targetPosition.Y < 0) || (targetPosition.Y >= oGL.Height)) return; if ((targetPosition.X + targetSize.Width < 0) || (targetPosition.X + targetSize.Width >= oGL.Width)) return; if ((targetPosition.Y + targetSize.Height < 0) || (targetPosition.Y + targetSize.Height >= oGL.Height)) return;*/ glEnable2D(); glEnable(Gl.GL_ALPHA); OGLTools.glEnable(Gl.GL_TEXTURE_2D); Gl.glEnable(Gl.GL_BLEND); Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA); Gl.glColor4f(1.0f, 1.0f, 1.0f, Alpha); Gl.glPushMatrix(); Gl.glTranslated(targetPosition.X, targetPosition.Y, 0); if (m_CurrentTextureID != (int)txt.TextureId) { m_CurrentTextureID = (int)txt.TextureId; Gl.glBindTexture(Gl.GL_TEXTURE_2D, m_CurrentTextureID); } float x1, y1; Gl.glBegin(Gl.GL_QUADS); // Extract bottom left position //x1 = (1.0f / (float)txt.Size.Width * (float)texturePosition.X) - txt.Size.GetFloatingX(textureSize.Width - txt.Size.Width); //y1 = (1.0f / (float)txt.Size.Height * (float)texturePosition.Y) - txt.Size.GetFloatingY(textureSize.Width - txt.Size.Height); x1 = 1 / (float)txt.Size.Width * (float)texturePosition.X; y1 = 1 / (float)txt.Size.Height * (float)texturePosition.Y; Gl.glTexCoord2f(x1, y1 * -1); Gl.glVertex2i(0, 0); // Extract bottom right //x1 = (1.0f / (float)txt.Size.Width * (float)texturePosition.X) - txt.Size.GetFloatingX(textureSize.Width); //y1 = (1.0f / (float)txt.Size.Height * (float)texturePosition.Y) - txt.Size.GetFloatingY(textureSize.Height - txt.Size.Height); x1 = 1 / (float)txt.Size.Width * ((float)texturePosition.X + (float)textureSize.Width); y1 = 1 / (float)txt.Size.Height * (float)texturePosition.Y; Gl.glTexCoord2f(x1, y1 * -1); Gl.glVertex2i(targetSize.Width, 0); // Extract top right //x1 = (1.0f / (float)txt.Size.Width * (float)texturePosition.X) - txt.Size.GetFloatingX(textureSize.Width); //y1 = (1.0f / (float)txt.Size.Height * (float)texturePosition.Y) - txt.Size.GetFloatingY(textureSize.Height); x1 = 1 / (float)txt.Size.Width * ((float)texturePosition.X + (float)textureSize.Width); y1 = 1 / (float)txt.Size.Height * ((float)texturePosition.Y + (float)textureSize.Height); Gl.glTexCoord2f(x1, y1 * -1); Gl.glVertex2i(targetSize.Width, targetSize.Height); // Extract top left position //x1 = (1.0f / (float)txt.Size.Width * (float)texturePosition.X) - txt.Size.GetFloatingX(textureSize.Width - txt.Size.Width); //y1 = (1.0f / (float)txt.Size.Height * (float)texturePosition.Y) - txt.Size.GetFloatingY(textureSize.Height); x1 = 1 / (float)txt.Size.Width * (float)texturePosition.X; y1 = 1 / (float)txt.Size.Height * ((float)texturePosition.Y + (float)textureSize.Height); Gl.glTexCoord2f(x1, y1 * -1); Gl.glVertex2i(0, targetSize.Height + 0); Gl.glEnd(); // disable blending glDisable(Gl.GL_BLEND); Gl.glPopMatrix(); // Need to optimize this like glPopMatrix(sessionID); }