static Texture Make2DTexture(Bitmap bmp, float x1, float y1) { using ( bmp ) { int textureID = GLUtils.LoadTexture(bmp); return(new Texture(textureID, x1, y1, bmp.Width, bmp.Height)); } }
static TextElement MakeTextElement(string text, float fontSize, int x1, int y1) { Font font = new Font("Times New Roman", fontSize); float totalwidth = 0; float totalheight = 0; using (Bitmap measuringBmp = new Bitmap(1, 1)) { using (Graphics g = Graphics.FromImage(measuringBmp)) { SizeF size = g.MeasureString(text, font); totalwidth = size.Width; totalheight = size.Height; } } Brush textBrush = new SolidBrush(Color.White); Bitmap bmp = new Bitmap((int)totalwidth, (int)totalheight); using (Graphics g2 = Graphics.FromImage(bmp)) { g2.DrawString(text, font, textBrush, 0, 0); } textBrush.Dispose(); font.Dispose(); using ( bmp ) { int textureID = GLUtils.LoadTexture(bmp); return(new TextElement(textureID, x1, y1, bmp.Width, bmp.Height, text)); } }
static Element Make2DTexture(Bitmap bmp, float x1, float y1, float width, float height) { using ( bmp ) { int textureID = GLUtils.LoadTexture(bmp); return(new Element(textureID, x1, y1, width, height)); } }
public int Make2DTexture(Bitmap bmp, float x1, float y1, float width, float height) { using ( bmp ) { int textureID = GLUtils.LoadTexture(bmp); Texture texture = new Texture(textureID, x1, y1, width, height); textures.Add(textureID, texture); return(textureID); } }
protected override void OnRenderFrame(FrameEventArgs e) { base.OnRenderFrame(e); GL.ClearColor(0.0f, 0.0f, 0.0f, 1.0f); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.MatrixMode(MatrixMode.Modelview); Matrix4 modelView = Matrix4.Identity; modelView *= Matrix4.CreateRotationZ(ToRadians(rotZ)); modelView *= Matrix4.CreateRotationY(ToRadians(rotY)); modelView *= Matrix4.CreateRotationX(ToRadians(rotX)); //modelView *= Matrix4.CreateRotationY( ToRadians( 45f ) ); // 35f modelView *= Matrix4.CreateRotationX(ToRadians(45f)); // was 60 ModelView = modelView; GL.LoadMatrix(ref modelView); UpdateCulling(); //GL.PolygonMode( MaterialFace.FrontAndBack, PolygonMode.Line ); //GL.Disable( EnableCap.DepthTest ); RenderTestMap(); //GL.Enable( EnableCap.DepthTest ); //GL.PolygonMode( MaterialFace.FrontAndBack, PolygonMode.Fill ); GL.Color3(1f, 1f, 1f); GLUtils.Mode2D(width, height); renderer2d.Render(); //gui.Render(); GLUtils.Mode3D(); /*GL.Color3( 1f, 0f, 0f ); * GL.LineWidth( 3 ); * GL.Begin( BeginMode.LineStrip ); * * Vector2 mousePos = new Vector2( Mouse.X, Mouse.Y ); * foreach( var pos in GLUtils.UnProject( Projection, ModelView, this, mousePos ) ) { * GL.Vertex3( pos.X, pos.Y, pos.Z ); * //GL.Vertex3( pos.Pos2.X, pos.Pos2.Y, pos.Pos2.Z ); * * } * //GL.Vertex3( pos.X, pos.Y, pos.Z ); * //GL.Vertex3( pos.X + 1, pos.Y, pos.Z ); * //GL.Vertex3( pos.X + 1, pos.Y, pos.Z + 1 ); * //GL.Vertex3( pos.X, pos.Y, pos.Z + 1 ); * GL.End();*/ GL.Color3(1f, 1f, 1f); UpdateTitleFps(e); SwapBuffers(); }
void MouseButtonDown(object sender, MouseButtonEventArgs e) { if (gui != null && gui.ClickIsInInterface(e.X, e.Y)) { gui.OnGuiMouseClick(e); } else { // TODO: Clicking on the game map. Vector2 mousePos = new Vector2(Mouse.X, Mouse.Y); GLUtils.UnProject(Projection, ModelView, this, mousePos); } }
public ButtonElement(int id, float x, float y, string text) : base(id, x, y, buttonSize, buttonSize) { if (text != null) { textElement = MakeTextElement(text, 12, (int)(x + buttonSize * 1.5f), (int)y); textElement.ShouldRenderBackground = false; Width += textElement.Width + buttonSize; ElementWidth = Width; } if (selectedTexture == -1) { selectedTexture = GLUtils.LoadTextureFile("buttonpressed.png"); notSelectedTexture = GLUtils.LoadTextureFile("buttonnotpressed.png"); } }
public void RenderBarracks() { if (keepId == -1) { keepData = Make2DTexture(new Bitmap("5b.bmp"), 0, 0); barracksData = Make2DTexture(new Bitmap("5.bmp"), 0, 0); keep2Data = Make2DTexture(new Bitmap("13.bmp"), 0, 0); keepId = keepData.ID; barracksId = barracksData.ID; keep2Id = keep2Data.ID; } Mode2D(); GL.Enable(EnableCap.Texture2D); GL.Disable(EnableCap.DepthTest); GL.BindTexture(TextureTarget.Texture2D, keepId); Texture texture = keepData; GL.Begin(BeginMode.Quads); RenderSprite(texture.X1, texture.Y1, texture.Width, texture.Height); //RenderSprite( texture.X1 + 2, texture.Y1, texture.Width, texture.Height ); GL.End(); //GL.BindTexture( TextureTarget.Texture2D, barracksId ); //texture = barracksData; //GL.Begin( BeginMode.Quads ); //RenderSprite( texture.X1, texture.Y1, texture.Width, texture.Height ); //GL.End(); GL.BindTexture(TextureTarget.Texture2D, keep2Id); texture = keep2Data; GL.Begin(BeginMode.Quads); RenderSprite(texture.X1 + 2, texture.Y1, texture.Width, texture.Height); GL.End(); GL.Enable(EnableCap.DepthTest); GL.Disable(EnableCap.Texture2D); GLUtils.Mode3D(); /*const float horSize = 3, verSize = 2f; * float height = -1.5f; * float x1 = 0, y1 = 0, * x2 = horSize, y2 = 0, * x3 = horSize, y3 = verSize, * x4 = 0, y4 = verSize; * * * GL.Disable( EnableCap.DepthTest ); * TranslatePoint( ref x1, ref y1 ); * TranslatePoint( ref x2, ref y2 ); * TranslatePoint( ref x3, ref y3 ); * TranslatePoint( ref x4, ref y4 ); * * GL.PolygonMode( MaterialFace.FrontAndBack, PolygonMode.Line ); * GL.Begin( BeginMode.Quads ); * GL.Vertex3( x1, height + 1, y1 ); * GL.Vertex3( x2, height + 1, y2 ); * GL.Vertex3( x3, height + 1, y3 ); * GL.Vertex3( x4, height + 1, y4 ); * GL.End(); * GL.PolygonMode( MaterialFace.FrontAndBack, PolygonMode.Fill ); * GL.Enable( EnableCap.DepthTest );*/ }
public static int MakeTerrainTexture() { // 28 images // 4 x 7 const int horElements = 28; const int verElements = 1; Console.WriteLine("MAX:" + GLUtils.MaxTextureDimensions); Bitmap textureAtlas = new Bitmap(xWidth * horElements, yWidth * verElements); using (Graphics g = Graphics.FromImage(textureAtlas)) { //DrawPart( g, "5555.png", xWidth * 0, 0 ); DrawPart(g, "grass1.gif", xWidth * 0, 0); DrawPart(g, "watershallow.gif", xWidth * 1, 0); DrawPart(g, "beach.gif", xWidth * 2, 0); DrawPart(g, "dirt3.gif", xWidth * 3, 0); DrawPart(g, "shallows.gif", xWidth * 4, 0); DrawPart(g, "leaves.gif", xWidth * 5, 0); DrawPart(g, "dirt1.gif", xWidth * 6, 0); DrawPart(g, "farm.gif", xWidth * 7, 0); DrawPart(g, "deadfarm.gif", xWidth * 8, 0); DrawPart(g, "grass3.gif", xWidth * 9, 0); DrawPart(g, "dirt2.gif", xWidth * 10, 0); DrawPart(g, "grass2.gif", xWidth * 11, 0); DrawPart(g, "desert.gif", xWidth * 12, 0); DrawPart(g, "deepwater.gif", xWidth * 13, 0); DrawPart(g, "mediumwater.gif", xWidth * 14, 0); DrawPart(g, "road.gif", xWidth * 15, 0); DrawPart(g, "roadbroken.gif", xWidth * 16, 0); DrawPart(g, "newfarm.gif", xWidth * 17, 0); DrawPart(g, "farmsmallplants.gif", xWidth * 18, 0); DrawPart(g, "farmlargeplants.gif", xWidth * 19, 0); DrawPart(g, "snow.gif", xWidth * 20, 0); DrawPart(g, "snowdirt.gif", xWidth * 21, 0); DrawPart(g, "snowgrass.gif", xWidth * 22, 0); DrawPart(g, "ice.gif", xWidth * 23, 0); DrawPart(g, "snowroad.gif", xWidth * 24, 0); DrawPart(g, "roadfungus.gif", xWidth * 25, 0); //DrawPart( g, "shallows.gif", 0, 49 ); //DrawPart( g, "leaves.gif", 97, 49 ); //DrawPart( g, "dirt1.gif", 194, 49 ); //DrawPart( g, "farm.gif", 291, 49 ); } Bitmap bmp = textureAtlas; /*for( int i = 0; i < bmp.Width; i++ ) { * for( int j = 0; j < bmp.Height; j++ ) { * if( bmp.GetPixel( i, j ) == Color.FromArgb( 255, 0, 0, 0 ) ) { * Console.WriteLine( "GGGG" ); * bmp.SetPixel( i, j, Color.FromArgb( 0, 0, 0, 0 ) ); * } * } * }*/ AokTerrainLocations = new RectangleF[41]; //for( int i = 0; i < AokTerrainLocations.Length; i++ ) { // AokTerrainLocations[i] = TextureCoords2d( 0, horElements, verElements ); //} AokTerrainLocations[0] = TextureCoords2d(0, horElements, verElements); AokTerrainLocations[1] = TextureCoords2d(1, horElements, verElements); AokTerrainLocations[2] = TextureCoords2d(2, horElements, verElements); AokTerrainLocations[3] = TextureCoords2d(3, horElements, verElements); AokTerrainLocations[4] = TextureCoords2d(4, horElements, verElements); AokTerrainLocations[5] = TextureCoords2d(5, horElements, verElements); AokTerrainLocations[6] = TextureCoords2d(6, horElements, verElements); AokTerrainLocations[7] = TextureCoords2d(7, horElements, verElements); AokTerrainLocations[8] = TextureCoords2d(8, horElements, verElements); AokTerrainLocations[9] = TextureCoords2d(9, horElements, verElements); AokTerrainLocations[10] = TextureCoords2d(5, horElements, verElements); AokTerrainLocations[11] = TextureCoords2d(10, horElements, verElements); AokTerrainLocations[12] = TextureCoords2d(11, horElements, verElements); AokTerrainLocations[13] = TextureCoords2d(5, horElements, verElements); AokTerrainLocations[14] = TextureCoords2d(12, horElements, verElements); AokTerrainLocations[15] = TextureCoords2d(14, horElements, verElements); AokTerrainLocations[16] = TextureCoords2d(0, horElements, verElements); AokTerrainLocations[17] = TextureCoords2d(5, horElements, verElements); AokTerrainLocations[18] = TextureCoords2d(5, horElements, verElements); AokTerrainLocations[19] = TextureCoords2d(5, horElements, verElements); AokTerrainLocations[20] = TextureCoords2d(5, horElements, verElements); AokTerrainLocations[21] = TextureCoords2d(22, horElements, verElements); AokTerrainLocations[22] = TextureCoords2d(13, horElements, verElements); AokTerrainLocations[23] = TextureCoords2d(14, horElements, verElements); AokTerrainLocations[24] = TextureCoords2d(15, horElements, verElements); AokTerrainLocations[25] = TextureCoords2d(16, horElements, verElements); AokTerrainLocations[26] = TextureCoords2d(23, horElements, verElements); AokTerrainLocations[27] = TextureCoords2d(10, horElements, verElements); AokTerrainLocations[28] = TextureCoords2d(14, horElements, verElements); AokTerrainLocations[29] = TextureCoords2d(17, horElements, verElements); AokTerrainLocations[30] = TextureCoords2d(18, horElements, verElements); AokTerrainLocations[31] = TextureCoords2d(19, horElements, verElements); AokTerrainLocations[32] = TextureCoords2d(20, horElements, verElements); AokTerrainLocations[33] = TextureCoords2d(21, horElements, verElements); AokTerrainLocations[34] = TextureCoords2d(22, horElements, verElements); AokTerrainLocations[35] = TextureCoords2d(23, horElements, verElements); AokTerrainLocations[36] = TextureCoords2d(21, horElements, verElements); AokTerrainLocations[37] = TextureCoords2d(23, horElements, verElements); AokTerrainLocations[38] = TextureCoords2d(24, horElements, verElements); AokTerrainLocations[39] = TextureCoords2d(25, horElements, verElements); AokTerrainLocations[20] = TextureCoords2d(15, horElements, verElements); invalidTerrainTexRec = TextureCoords2d(27, horElements, verElements); //Bitmap bmp = new Bitmap( bmpWidth, bmpHeight ); //using( Graphics g = Graphics.FromImage( bmp ) ) { //} return(GLUtils.LoadTexture(textureAtlas)); }