/// <summary> /// Sets the attributes. /// </summary> /// <param name="gl">The OpenGL instance.</param> public override void SetAttributes(OpenGL gl) { if(enableAlphaTest.HasValue && alphaTestFunction.HasValue && alphaTestReferenceValue.HasValue) { gl.EnableIf(OpenGL.GL_ALPHA_TEST, enableAlphaTest.Value); gl.AlphaFunc(alphaTestFunction.Value, alphaTestReferenceValue.Value); } if(enableBlend.HasValue && blendingSourceFactor.HasValue && blendingDestinationFactor.HasValue) { gl.EnableIf(OpenGL.GL_BLEND, enableBlend.Value); gl.BlendFunc(blendingSourceFactor.Value, blendingDestinationFactor.Value); } if(enableDither.HasValue) gl.EnableIf(OpenGL.GL_DITHER, enableDither.Value); if(drawBufferMode.HasValue) gl.DrawBuffer(drawBufferMode.Value); if(enableLogicOp.HasValue && logicOp.HasValue) { gl.EnableIf(OpenGL.GL_COLOR_LOGIC_OP, enableLogicOp.Value); gl.LogicOp(logicOp.Value); } if(colorModeClearColor != null) gl.ClearColor(colorModeClearColor.R, colorModeClearColor.G, colorModeClearColor.B, colorModeClearColor.A); //todowritemask }
/// <summary> /// Handles the OpenGLInitialized event of the openGLControl control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void openGLControl_OpenGLInitialized(object sender, EventArgs e) { // Get the OpenGL object. OpenGL gl = openGLControl.OpenGL; // Set the clear color. gl.ClearColor(0, 0, 0, 0); gl.ShadeModel(OpenGL.GL_SMOOTH); // Enables Smooth Color Shading gl.ClearDepth(1.0); // Depth Buffer Setup gl.Enable(OpenGL.GL_DEPTH_TEST); // Enable Depth Buffer gl.DepthFunc(OpenGL.GL_LESS); // The Type Of Depth Test To Do gl.Enable(OpenGL.GL_ALPHA_TEST); gl.AlphaFunc(OpenGL.GL_GREATER, 0.4f); gl.Hint(OpenGL.GL_PERSPECTIVE_CORRECTION_HINT, OpenGL.GL_NICEST); //Realy Nice perspective calculations gl.Enable(OpenGL.GL_TEXTURE_2D); // Enable Texture Mapping // Create our texture object from a file. This creates the texture for OpenGL. texFont.Create(gl, "FontLines2.png"); texBackground.Create(gl, "galaxy.jpg"); TexCube.Create(gl, "texture.jpg"); TexEarth.Create(gl, "earth.jpg"); xSpeed = 0.9f; // start with some movement ySpeed = 0.9f; zSpeed = 0.9f; xScrollSpeed = 0.005f; g_TextScroller = -1.5f; g_TextScroller2 = -1.5f; g_Zcube = -15.5f; CreateSphere(0, 0, 0, 10, 48); }
/// <summary> /// Sets the attributes. /// </summary> /// <param name="gl">The OpenGL instance.</param> public override void SetAttributes(OpenGL gl) { if (enableAlphaTest.HasValue && alphaTestFunction.HasValue && alphaTestReferenceValue.HasValue) { gl.EnableIf(OpenGL.GL_ALPHA_TEST, enableAlphaTest.Value); gl.AlphaFunc(alphaTestFunction.Value, alphaTestReferenceValue.Value); } if (enableBlend.HasValue && blendingSourceFactor.HasValue && blendingDestinationFactor.HasValue) { gl.EnableIf(OpenGL.GL_BLEND, enableBlend.Value); gl.BlendFunc(blendingSourceFactor.Value, blendingDestinationFactor.Value); } if (enableDither.HasValue) { gl.EnableIf(OpenGL.GL_DITHER, enableDither.Value); } if (drawBufferMode.HasValue) { gl.DrawBuffer(drawBufferMode.Value); } if (enableLogicOp.HasValue && logicOp.HasValue) { gl.EnableIf(OpenGL.GL_COLOR_LOGIC_OP, enableLogicOp.Value); gl.LogicOp(logicOp.Value); } if (colorModeClearColor != null) { gl.ClearColor(colorModeClearColor.R, colorModeClearColor.G, colorModeClearColor.B, colorModeClearColor.A); } //todowritemask }
private void MainWindow_Load(object sender, EventArgs e) { //生成地图 world.CreateMap(); toX = world.person.X; toY = world.person.Y; gl = glc.OpenGL; gl.ClearColor(world.skycolorR, world.skycolorG, world.skycolorB, 0.5f); gl.Enable(OpenGL.GL_ALPHA_TEST); //透明部分测试 gl.AlphaFunc(OpenGL.GL_GREATER, 0.1f); gl.Enable(OpenGL.GL_BLEND);//启用混合 gl.BlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA); //gl.ShadeModel(OpenGL.GL_SMOOTH);//允许平滑着色 //添加纹理到纹理数组 Texture textrue = new Texture(); textrue.Create(gl, new Bitmap((Image)rm.GetObject("p"))); textrued.Add("p", textrue); textrue = new Texture(); textrue.Create(gl, new Bitmap((Image)rm.GetObject("p2"))); textrued.Add("p2", textrue); for (int i = 1; i < 15; i++) { textrue = new Texture(); textrue.Create(gl, new Bitmap((Image)rm.GetObject("_" + i))); textrued.Add("" + i, textrue); } MainWindow_Resize(sender, e); }
/// <summary> /// Handles the OpenGLInitialized event of the openGLControl control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void openGLControl_OpenGLInitialized(object sender, EventArgs e) { // Get the OpenGL object. OpenGL gl = openGLControl.OpenGL; gl.ShadeModel(OpenGL.GL_SMOOTH); // Enables Smooth Color Shading gl.ClearDepth(1.0); // Depth Buffer Setup gl.Enable(OpenGL.GL_DEPTH_TEST); // Enable Depth Buffer gl.DepthFunc(OpenGL.GL_LESS); // The Type Of Depth Test To Do gl.Enable(OpenGL.GL_ALPHA_TEST); gl.AlphaFunc(OpenGL.GL_GREATER, 0.4f); gl.Hint(OpenGL.GL_PERSPECTIVE_CORRECTION_HINT, OpenGL.GL_NICEST); //Realy Nice perspective calculations gl.Enable(OpenGL.GL_TEXTURE_2D); // Enable Texture Mapping // Create our texture object from a file. This creates the texture for OpenGL. texFont.Create(gl, "FontLines2.png"); xScrollSpeed = 0.025f; g_TextScroller2 = 1.0f; // Set the clear color. gl.ClearColor(0, 0, 0, 0); }
public void draw(OpenGL gl)//Рисование бота { if (isDie && !this.world.isShowDied) { return; } gl.Color(this.getColor()); /* * gl.Begin(OpenGL.GL_POLYGON); * gl.Vertex(this.x * world.cellWidth, this.y*world.cellHeight); * gl.Vertex(this.x* world.cellWidth + world.cellWidth, this.y * world.cellHeight); * gl.Vertex(this.x * world.cellWidth + world.cellWidth , this.y * world.cellHeight + world.cellHeight); * gl.Vertex(this.x*world.cellWidth , this.y*world.cellHeight+ world.cellHeight); * gl.End();*/ gl.PushMatrix(); gl.Enable(OpenGL.GL_ALPHA_TEST); gl.AlphaFunc(OpenGL.GL_GREATER, .8f); gl.Enable(OpenGL.GL_TEXTURE_2D); gl.Translate(this.x * world.cellWidth + world.cellWidth / 2, this.y * world.cellHeight + world.cellHeight / 2, 0); gl.Rotate(this.getAngle(), 0, 0, 1); gl.Begin(BeginMode.Quads); gl.TexCoord(0, 1); gl.Vertex(-world.cellWidth / 2, -world.cellHeight / 2); gl.TexCoord(1, 1); gl.Vertex(-world.cellWidth / 2 + world.cellWidth, -world.cellHeight / 2); gl.TexCoord(1, 0); gl.Vertex(-world.cellWidth / 2 + world.cellWidth, -world.cellHeight / 2 + world.cellHeight); gl.TexCoord(0, 0); gl.Vertex(-world.cellWidth / 2, -world.cellHeight / 2 + world.cellHeight); gl.End(); gl.Disable(OpenGL.GL_TEXTURE_2D); gl.Disable(OpenGL.GL_ALPHA_TEST); gl.PopMatrix(); }
void Blend(OpenGL gl, int geoset, int layer) { switch (model.Blending[FindBlend(geoset, layer)]) { case 1: gl.Enable(OpenGL.GL_BLEND); gl.Enable(OpenGL.GL_ALPHA_TEST); gl.BlendFunc(OpenGL.GL_ONE, OpenGL.GL_ZERO); gl.AlphaFunc(OpenGL.GL_GREATER, 0.9f); break; case 2: gl.Enable(OpenGL.GL_BLEND); gl.DepthMask((byte)OpenGL.GL_FALSE); gl.BlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA); break; case 4: gl.Enable(OpenGL.GL_BLEND); gl.DepthMask((byte)OpenGL.GL_FALSE); gl.BlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE); break; case 5: gl.Enable(OpenGL.GL_BLEND); gl.DepthMask((byte)OpenGL.GL_FALSE); gl.BlendFunc(OpenGL.GL_DST_COLOR, OpenGL.GL_ZERO); break; case 6: gl.Enable(OpenGL.GL_BLEND); gl.DepthMask((byte)OpenGL.GL_FALSE); gl.BlendFunc(OpenGL.GL_DST_COLOR, OpenGL.GL_SRC_COLOR); break; } }
private void glcScene_OpenGLDraw(object sender, RenderEventArgs args) { switch (state) { case 0: #region 0 : 타이틀 #endregion break; case 1: case 2: case 3: #region 1 : 게임 / 2,3 : 게임 오버 OpenGL gl = glcScene.OpenGL; gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT); gl.ClearColor(0.8f, 0.8f, 0.8f, 1.0f); gl.BlendFunc(BlendingSourceFactor.SourceAlpha, BlendingDestinationFactor.OneMinusSourceAlpha); gl.LoadIdentity(); gl.MatrixMode(MatrixMode.Projection); gl.Perspective(60.0, (double)this.Width / this.Height, 0.01, 1000.0); gl.LookAt(0, player.y - 4, 5, 0, player.y + 3, 0, 0, 0, 1); gl.Enable(OpenGL.GL_TEXTURE_2D); for (int i = -3; i < 3; i++) { for (int j = (int)player.y - 10; j < (int)player.y + 50; j++) { if ((i + 2 * j) % 4 == 0) { texFloor2.Bind(gl); } else { texFloor1.Bind(gl); } gl.Begin(BeginMode.Quads); { gl.TexCoord(0, 0); gl.Vertex(i, j, 0); gl.TexCoord(0, 1); gl.Vertex(i, j + 1, 0); gl.TexCoord(1, 1); gl.Vertex(i + 1, j + 1, 0); gl.TexCoord(1, 0); gl.Vertex(i + 1, j, 0); } gl.End(); } } if (player.y < 20) { texStart.Bind(gl); gl.Begin(BeginMode.Quads); { gl.TexCoord(0, 1); gl.Vertex(-2, 3, 3); gl.TexCoord(0, 0); gl.Vertex(-2, 3, 4); gl.TexCoord(1, 0); gl.Vertex(2, 3, 4); gl.TexCoord(1, 1); gl.Vertex(2, 3, 3); } gl.End(); } else if (player.y % 500 > 450 || player.y % 500 < 50) { int yy = (int)((player.y + 250) / 500) * 500; texCheck.Bind(gl); gl.Begin(BeginMode.Quads); { gl.TexCoord(0, 1); gl.Vertex(-2, yy, 3); gl.TexCoord(0, 0); gl.Vertex(-2, yy, 4); gl.TexCoord(1, 0); gl.Vertex(2, yy, 4); gl.TexCoord(1, 1); gl.Vertex(2, yy, 3); } gl.End(); } gl.Disable(OpenGL.GL_TEXTURE_2D); /* * gl.Color(0.0f, 0.0f, 0.0f, 0.5f); * * gl.Enable(OpenGL.GL_BLEND); * foreach (Walker w in walkers) * { * gl.Begin(BeginMode.Polygon); * { * for (int i = 0; i < 16; i++) * { * gl.Vertex(w.xpos * 0.5f + w.flying + 0.35 * Math.Cos(i * Math.PI / 8), w.y + 0.35 * Math.Sin(i * Math.PI / 8), 0.1); * } * } * gl.End(); * } * gl.Disable(OpenGL.GL_BLEND); */ gl.Enable(OpenGL.GL_TEXTURE_2D); int wi = 18, hi = 4; for (int j = (int)((player.y - 40) / wi) * wi; j <= (int)((player.y + 20) / wi) * wi; j += wi) { texBuilding[(j / wi + 100) % 4].Bind(gl); if ((j / wi - 3) % 11 == 10) { gl.Color(0.5f, 0.5f, 0.5f, 1.0f); } else { gl.Color(1.0f, 1.0f, 1.0f, 1.0f); } gl.Begin(BeginMode.Quads); { gl.TexCoord(0, 1); gl.Vertex(-3, j, 0); gl.TexCoord(1, 1); gl.Vertex(-3, j + wi, 0); gl.TexCoord(1, 0); gl.Vertex(-3, j + wi, hi); gl.TexCoord(0, 0); gl.Vertex(-3, j, hi); } gl.End(); texBuilding[(j / wi + 102) % 4].Bind(gl); gl.Begin(BeginMode.Quads); { gl.TexCoord(1, 1); gl.Vertex(3, j, 0); gl.TexCoord(0, 1); gl.Vertex(3, j + wi, 0); gl.TexCoord(0, 0); gl.Vertex(3, j + wi, hi); gl.TexCoord(1, 0); gl.Vertex(3, j, hi); } gl.End(); } gl.Color(1.0f, 1.0f, 1.0f, 1.0f); gl.Enable(OpenGL.GL_BLEND); gl.Enable(OpenGL.GL_ALPHA_TEST); gl.AlphaFunc(AlphaTestFunction.Great, 0.1f); texF.Bind(gl); foreach (Walker w in walkers) { if (w.type == WalkerType.Female && w.flying == 0) { w.Draw3D(gl); } } texM.Bind(gl); foreach (Walker w in walkers) { if (w.type == WalkerType.Male && w.flying == 0) { w.Draw3D(gl); } } texFFly.Bind(gl); foreach (Walker w in walkers) { if (w.type == WalkerType.Female && w.flying != 0) { w.Draw3DFlying(gl); } } texMFly.Bind(gl); foreach (Walker w in walkers) { if (w.type == WalkerType.Male && w.flying != 0) { w.Draw3DFlying(gl); } } texrun.Bind(gl); player.Draw3D(gl); gl.Disable(OpenGL.GL_TEXTURE_2D); gl.LoadIdentity(); gl.Disable(OpenGL.GL_ALPHA_TEST); gl.Disable(OpenGL.GL_BLEND); gl.Flush(); #endregion break; } }