public override void SetRenderData(STGenericMaterial mat, ShaderProgram shader, STGenericObject m) { var cmbMaterial = ((CMB.CMBMaterialWrapper)mat).Material; var cmbMesh = ((CMB.CmbMeshWrapper)m); bool HasNoNormals = cmbMesh.Shape.Normal.VertexData == null || cmbMesh.Shape.Normal.VertexData.Length == 0; shader.SetBoolToInt("HasNoNormals", HasNoNormals); shader.SetBoolToInt("isTransparent", cmbMaterial.BlendEnaled); SetGLCullMode(cmbMaterial.CullMode); GL.Enable(EnableCap.Blend); GL.BlendFunc(cmbMaterial.BlendingFactorSrcAlpha, cmbMaterial.BlendingFactorDestAlpha); GL.BlendColor(1.0f, 1.0f, 1.0f, cmbMaterial.BlendColorA); if (cmbMaterial.AlphaTestEnable) { GL.Enable(EnableCap.AlphaTest); } else { GL.Disable(EnableCap.AlphaTest); } GL.AlphaFunc(cmbMaterial.AlphaTestFunction, cmbMaterial.AlphaTestReference); }
private void RenderStart() { GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); GL.Viewport(0, 0, simpleOpenGlControl1.Width, simpleOpenGlControl1.Height); RectangleF r = GetDisplayRect(true); GL.Ortho( r.Left, r.Right, r.Bottom, r.Top, -8192, 8192); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); GL.ClearColor(1, 1, 1, 1f); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Color4(1, 1, 1, 1); GL.Enable(EnableCap.Texture2D); GL.BindTexture(TextureTarget.Texture2D, 0); GL.Color4(1, 1, 1, 1); GL.Disable(EnableCap.CullFace); GL.Enable(EnableCap.AlphaTest); GL.Enable(EnableCap.Blend); GL.Enable(EnableCap.PointSmooth); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); GL.AlphaFunc(AlphaFunction.Always, 0f); GL.LoadIdentity(); }
private void GlcontrolOnPaint(object sender, PaintEventArgs e) { this.glcontrol.MakeCurrent(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Enable(EnableCap.AlphaTest); GL.AlphaFunc(AlphaFunction.Greater, 0.05f); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); GL.MatrixMode(MatrixMode.Texture); GL.LoadIdentity(); //Rotate and translate GL.Translate(0.5, 0.5, 0.5); GL.Scale(scaleRate, -scaleRate, (double)renderer.mImageWidth / (double)renderer.mImageCount * scaleRate); GL.MultMatrix(renderer.mdRotation); GL.Translate(-0.5, -0.5, -0.5); GL.Enable(EnableCap.Texture3DExt); GL.BindTexture(TextureTarget.Texture3D, mTextId); GL.CallList(this.displayList); this.glcontrol.SwapBuffers(); this.frames++; }
protected virtual void On_Load(object sender, EventArgs e) { m_GLLoaded = true; GL.Viewport(ClientRectangle); float ratio = (float)Width / (float)Height; GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); m_ProjectionMatrix = Matrix4.CreatePerspectiveFieldOfView((float)((70.0f * Math.PI) / 180.0f), ratio, 0.01f, 1000.0f); GL.MultMatrix(ref m_ProjectionMatrix); m_PixelFactorX = ((2f * (float)Math.Tan((35f * Math.PI) / 180f) * ratio) / (float)(Width)); m_PixelFactorY = ((2f * (float)Math.Tan((35f * Math.PI) / 180f)) / (float)(Height)); GL.Enable(EnableCap.AlphaTest); GL.AlphaFunc(AlphaFunction.Greater, 0f); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.CullFace); GL.CullFace(CullFaceMode.Back); GL.Enable(EnableCap.Texture2D); GL.LineWidth(1.0f); m_CamRotation = new Vector2(0.0f, (float)Math.PI / 8.0f); m_CamTarget = new Vector3(0.0f, 0.0f, 0.0f); m_CamDistance = 1.0f; UpdateCamera(); GL.ClearColor(Color.FromArgb(0, 0, 32)); }
private static void SetupFixedFunctionRendering() { GL.UseProgram(0); GL.Enable(EnableCap.LineSmooth); // This is Optional GL.Enable(EnableCap.Normalize); // This is critical to have GL.Enable(EnableCap.RescaleNormal); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Lequal); GL.Enable(EnableCap.AlphaTest); GL.AlphaFunc(AlphaFunction.Gequal, 0.1f); GL.Enable(EnableCap.CullFace); GL.CullFace(CullFaceMode.Front); GL.Enable(EnableCap.LineSmooth); GL.Enable(EnableCap.StencilTest); GL.StencilOp(StencilOp.Keep, StencilOp.Keep, StencilOp.Replace); }
private void MDL0Viewer_Load(object sender, EventArgs e) { simpleOpenGlControl1.InitializeContexts(); //GL.Enable(EnableCap.Lighting); GL.Enable(EnableCap.RescaleNormal); GL.Enable(EnableCap.ColorMaterial); GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.Normalize); GL.Disable(EnableCap.CullFace); GL.FrontFace(FrontFaceDirection.Ccw); GL.Enable(EnableCap.Texture2D); GL.ClearDepth(1); GL.Enable(EnableCap.AlphaTest); GL.AlphaFunc(AlphaFunction.Greater, 0f); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); //GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, Gl.GL_BLEND); GL.ShadeModel(ShadingModel.Smooth); GL.DepthFunc(DepthFunction.Lequal); GL.ClearColor(51f / 255f, 51f / 255f, 51f / 255f, 0f); init = true; Render(); }
protected override void OnLoad(EventArgs e) { GL.ClearColor(Color4.Black); GL.Enable(EnableCap.Blend); GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.ColorMaterial); GL.Enable(EnableCap.Light0); GL.Light(LightName.Light0, LightParameter.Ambient, new Color4(0.3f, 0.3f, 0.3f, 1.0f)); GL.Light(LightName.Light0, LightParameter.Diffuse, new Color4(0.8f, 0.8f, 0.8f, 1.0f)); GL.ColorMaterial(MaterialFace.Front, ColorMaterialParameter.AmbientAndDiffuse); GL.AlphaFunc(AlphaFunction.Greater, 0.1f); GL.Fog(FogParameter.FogMode, (int)FogMode.Linear); GL.Fog(FogParameter.FogColor, new float[] { 0.0f, 0.0f, 0.0f, 1.0f }); GL.Fog(FogParameter.FogStart, (World.RenderRange - 48.0f) * 0.75f); GL.Fog(FogParameter.FogEnd, World.RenderRange - 48.0f); if (!Ressources.Load()) { Exit(); } Font = new Font(Ressources.FontTexture); }
public override void Begin() { if (m_RestoreRenderState) { // Get previous parameter values before changing them. GL.GetInteger(GetPName.BlendSrc, out m_PrevBlendSrc); GL.GetInteger(GetPName.BlendDst, out m_PrevBlendDst); GL.GetInteger(GetPName.AlphaTestFunc, out m_PrevAlphaFunc); GL.GetFloat(GetPName.AlphaTestRef, out m_PrevAlphaRef); m_WasBlendEnabled = GL.IsEnabled(EnableCap.Blend); m_WasTexture2DEnabled = GL.IsEnabled(EnableCap.Texture2D); m_WasDepthTestEnabled = GL.IsEnabled(EnableCap.DepthTest); } // Set default values and enable/disable caps. GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.AlphaFunc(AlphaFunction.Greater, 1.0f); GL.Enable(EnableCap.Blend); GL.Disable(EnableCap.DepthTest); GL.Disable(EnableCap.Texture2D); m_VertNum = 0; m_DrawCallCount = 0; m_ClipEnabled = false; m_TextureEnabled = false; m_LastTextureID = -1; GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.ColorArray); GL.EnableClientState(ArrayCap.TextureCoordArray); GL.PushMatrix(); GL.Scale(Scale, Scale, 1); }
public override void End() { Flush(); if (m_RestoreRenderState) { GL.BindTexture(TextureTarget.Texture2D, 0); m_LastTextureID = 0; // Restore the previous parameter values. GL.BlendFunc((BlendingFactorSrc)m_PrevBlendSrc, (BlendingFactorDest)m_PrevBlendDst); GL.AlphaFunc((AlphaFunction)m_PrevAlphaFunc, m_PrevAlphaRef); if (!m_WasBlendEnabled) { GL.Disable(EnableCap.Blend); } if (m_WasTexture2DEnabled && !m_TextureEnabled) { GL.Enable(EnableCap.Texture2D); } if (m_WasDepthTestEnabled) { GL.Enable(EnableCap.DepthTest); } } GL.DisableClientState(ArrayCap.VertexArray); GL.DisableClientState(ArrayCap.ColorArray); GL.DisableClientState(ArrayCap.TextureCoordArray); GL.PopMatrix(); }
protected override void OnRenderFrame(FrameEventArgs e) { base.OnRenderFrame(e); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.ClearColor(Color.Black); GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.AlphaTest); GL.Enable(EnableCap.Blend); GL.Enable(EnableCap.SampleAlphaToCoverage); GL.AlphaFunc(AlphaFunction.Greater, 0.1f); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); _drawingContext2D.Drawables.Clear(); var text = new Text2D(Vector2.Zero, 0.0f, "Ala ma kota", new Font("Arial", 10.0f), Color.DeepSkyBlue, opacity); opacity += 2.0f / 60.0f; if (opacity > 1.0f) { opacity = 0.0f; } var button = new Button(text); _drawingContext2D.Drawables.Add(button); _drawingContext2D.Render(); SwapBuffers(); }
public override void OnRender(GLControl control) { GL.Enable(EnableCap.AlphaTest); GL.AlphaFunc(AlphaFunction.Gequal, 0.1f); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); }
private void InitialiseView() { GL.ClearColor(Color.LightBlue); GL.Enable(EnableCap.CullFace); GL.CullFace(CullFaceMode.Back); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Lequal); GL.Enable(EnableCap.AlphaTest); GL.AlphaFunc(AlphaFunction.Gequal, 0.05f); GL.Enable(EnableCap.ColorMaterial); GL.Enable(EnableCap.Normalize); GL.Enable(EnableCap.Texture2D); GL.ShadeModel(ShadingModel.Smooth); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); GL.Enable(EnableCap.Lighting); GL.Enable(EnableCap.Light0); #if DEBUG InitializeDebugMessages(); #endif }
public override void SetRenderData(STGenericMaterial mat, ShaderProgram shader, STGenericObject m) { var cmbMaterial = ((CMB.CMBMaterialWrapper)mat).CMBMaterial; var cmbMesh = ((CMB.CmbMeshWrapper)m); bool HasNoNormals = cmbMesh.Mesh.HasNormal == false; shader.SetBoolToInt("HasNoNormals", HasNoNormals); shader.SetBoolToInt("isTransparent", cmbMaterial.BlendEnabled); SetGLCullMode(cmbMaterial.CullMode); if (cmbMaterial.BlendEnabled) { GL.Enable(EnableCap.Blend); GL.BlendColor(cmbMaterial.BlendColor.R / 255, cmbMaterial.BlendColor.G / 255, cmbMaterial.BlendColor.B / 255, cmbMaterial.BlendColor.A / 255); GL.BlendFunc(ConvertBlendFunc(cmbMaterial.BlendFunction.AlphaSrcFunc), ConvertBlendFunc(cmbMaterial.BlendFunction.AlphaDstFunc)); } else { GL.Disable(EnableCap.Blend); } if (cmbMaterial.AlphaTest.Enabled) { GL.Enable(EnableCap.AlphaTest); GL.AlphaFunc(ConvertTestFunction(cmbMaterial.AlphaTest.Function), cmbMaterial.AlphaTest.Reference / 255f); } else { GL.Disable(EnableCap.AlphaTest); } }
public Text(string text, Vec2F pos, Vec2F extent) { this.text = text; shape = new StationaryShape(pos, extent); color = Color.Black; fontSize = 50; // create a texture id textureId = GL.GenTexture(); // bind this new texture id BindTexture(); // set texture properties, filters, blending functions, etc. GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.Linear); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Lequal); GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.AlphaTest); GL.AlphaFunc(AlphaFunction.Gequal, 0.5f); // unbind this new texture UnbindTexture(); // create a texture CreateBitmapTexture(); }
public override void Render(DateTime time) { //using(ModernOpenGl.SetColor(_Color, ShadingModel.Smooth)) //using (ModernOpenGl.Begin(PrimitiveType.Points)) //{ // Location.GLVertex3(); //} //GL.Clear(ClearBufferMask.ColorBufferBit); using (ModernOpenGl.SetColor(_Color, ShadingModel.Flat, solidBody: false)) { GL.PointSize(_Size); GL.Enable(EnableCap.AlphaTest); GL.AlphaFunc(AlphaFunction.Notequal, 0); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.Enable(EnableCap.PointSmooth); GL.Hint(HintTarget.PointSmoothHint, HintMode.Nicest); GL.Begin(PrimitiveType.Points); Location.GLVertex3(); GL.End(); GL.Disable(EnableCap.PointSmooth); GL.BlendFunc(BlendingFactorSrc.Zero, BlendingFactorDest.Zero); GL.Disable(EnableCap.Blend); } }
void IMVP.SetShaderProgram(mat4 mvp) { //this.tex.Bind(); GL.CullFace(GL.GL_FRONT_AND_BACK); GL.PolygonMode(PolygonModeFaces.FrontAndBack, PolygonModes.Filled); GL.Enable(GL.GL_ALPHA_TEST); GL.AlphaFunc(GL.GL_GREATER, alphaThreshold); bool blend = this.blend; if (blend) { GL.Enable(GL.GL_BLEND); GL.BlendFunc(sFactor, dFactor); } uint textureID = this.textureProcessor.GetTexture3D(); GL.BindTexture(GL.GL_TEXTURE_3D, textureID); this.shaderProgram.Bind(); this.shaderProgram.SetUniform("tex", textureID); IMVPHelper.SetMVP(this, mvp); }
//ウィンドウの起動時に実行される。 protected override void OnLoad(EventArgs e) { base.OnLoad(e); GL.ClearColor(Color4.Gray); GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.Texture2D); //アルファテストを許可 GL.Enable(EnableCap.AlphaTest); GL.AlphaFunc(AlphaFunction.Greater, 0.5f); //テクスチャ用バッファの生成 texture = GL.GenTexture(); //テクスチャ用バッファのひもづけ GL.BindTexture(TextureTarget.Texture2D, texture); //テクスチャの設定 GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); //picture.pngの読み込み Bitmap file = new Bitmap("02-04_picture.png"); //png画像の反転を直す file.RotateFlip(RotateFlipType.RotateNoneFlipY); //データ読み込み BitmapData data = file.LockBits(new Rectangle(0, 0, file.Width, file.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); //テクスチャ用バッファに色情報を流し込む GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0); }
public static void SetUp3DFixedFunctionRendering(Matrix4 mvpMatrix) { GL.UseProgram(0); // Manually set up the matrix for immediate mode. Matrix4 matrix = mvpMatrix; GL.MatrixMode(MatrixMode.Modelview); GL.LoadMatrix(ref matrix); GL.Enable(EnableCap.LineSmooth); // This is Optional GL.Enable(EnableCap.Normalize); // This is critical to have GL.Enable(EnableCap.RescaleNormal); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); GL.BlendEquation(BlendEquationMode.FuncAdd); GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Lequal); GL.Enable(EnableCap.AlphaTest); GL.AlphaFunc(AlphaFunction.Gequal, 0.1f); GL.Enable(EnableCap.CullFace); GL.CullFace(CullFaceMode.Front); GL.Enable(EnableCap.LineSmooth); GL.Enable(EnableCap.StencilTest); GL.StencilOp(StencilOp.Keep, StencilOp.Keep, StencilOp.Replace); }
internal void Loadtextures() { var content = $"{nameof(CG_Projekt)}.Content.Textures."; this.texPlayerPistol = Texture.Load(Resource.LoadStream(content + "PlayerPistol.png")); this.texPlayerShotgun = Texture.Load(Resource.LoadStream(content + "PlayerShotgun.png")); this.texPlayerUzi = Texture.Load(Resource.LoadStream(content + "PlayerUzi.png")); this.texEnemyWalk = Texture.Load(Resource.LoadStream(content + "enemywalkanimation.png")); this.texObstacle = Texture.Load(Resource.LoadStream(content + "rocks.png")); this.texHeartCollectible = Texture.Load(Resource.LoadStream(content + "heart.png")); this.texStart = Texture.Load(Resource.LoadStream(content + "Press.png")); this.texStartBlack = Texture.Load(Resource.LoadStream(content + "PressBlack.png")); this.texGrass = Texture.Load(Resource.LoadStream(content + "grass.png")); this.texFragment = Texture.Load(Resource.LoadStream(content + "debris.png")); this.texBlood = Texture.Load(Resource.LoadStream(content + "BloodNew.png")); this.texWater = Texture.Load(Resource.LoadStream(content + "water.jpg")); this.texHealth = Texture.Load(Resource.LoadStream(content + "healthbar.png")); this.texHealthBackground = Texture.Load(Resource.LoadStream(content + "healthbar -Background.png")); this.texAmmoPistol = Texture.Load(Resource.LoadStream(content + "ammoPistol.png")); this.texAmmoUzi = Texture.Load(Resource.LoadStream(content + "ammoUZI.png")); this.texAmmoShotgun = Texture.Load(Resource.LoadStream(content + "ammoShotgun.png")); this.texMissile = Texture.Load(Resource.LoadStream(content + "ammoMissile.png")); this.texBullet = Texture.Load(Resource.LoadStream(content + "bullet.png")); this.texPistol = Texture.Load(Resource.LoadStream(content + "Pistol.png")); this.texUzi = Texture.Load(Resource.LoadStream(content + "Uzi.png")); this.texShotgun = Texture.Load(Resource.LoadStream(content + "Shotgun.png")); this.texRPG = Texture.Load(Resource.LoadStream(content + "Rocketlauncher.png")); this.texfont = Texture.Load(Resource.LoadStream(content + "SilverFont.png")); GL.Enable(EnableCap.AlphaTest); GL.AlphaFunc(AlphaFunction.Greater, 0.2f); GL.Enable(EnableCap.Texture2D); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); GL.Enable(EnableCap.Blend); TexturesLoaded = true; }
private void MDL0Viewer_Load(object sender, EventArgs e) { simpleOpenGlControl1.InitializeContexts(); //GL.Enable(GL.GL_LIGHTING); GL.Enable(EnableCap.RescaleNormal); GL.Enable(EnableCap.ColorMaterial); GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.Normalize); GL.Disable(EnableCap.CullFace); GL.FrontFace(FrontFaceDirection.Ccw); GL.Enable(EnableCap.Texture2D); GL.ClearDepth(1); GL.Enable(EnableCap.AlphaTest); GL.AlphaFunc(AlphaFunction.Greater, 0f); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); //GL.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_BLEND); GL.ShadeModel(ShadingModel.Smooth); GL.DepthFunc(DepthFunction.Lequal); GL.ClearColor(51f / 255f, 51f / 255f, 51f / 255f, 0f); if (Resource.Data.Textures != null && Model != null) { int i = 0; foreach (var v in Model.Materials) { if (v.Tex0 != null) { UploadTex(v.Tex0, i * 4 + 0 + 1); } if (v.Tex1 != null) { UploadTex(v.Tex1, i * 4 + 1 + 1); } if (v.Tex2 != null) { UploadTex(v.Tex2, i * 4 + 2 + 1); } //if (v.Tex3 != null) UploadTex(v.Tex3, i * 4 + 3 + 1); i++; } } if (Model != null) { Shaders = new CGFXShader[Model.Materials.Length]; } //GlNitro.glNitroBindTextures(file, 1); glversion = GL.GetString(StringName.Version); init = true; Render(); }
public static void ball_draw_solid(float[] ball_M, float[] ball_bill_M, float t) { if (has_solid != 0) { int mask = (solid_flags & F_DEPTHMASK); int test = (solid_flags & F_DEPTHTEST); if (solid_alpha < 1.0f) { GL.Enable(EnableCap.AlphaTest); GL.AlphaFunc(AlphaFunction.Gequal, solid_alpha); } Video.MODELVIEW_PushMatrix(); { /* Apply the ball rotation. */ Video.MODELVIEW_MultMatrix(ball_M); /* Draw the solid billboard geometry. */ if (solid.m_rc != 0) { if (test == 0) { GL.Disable(EnableCap.DepthTest); } if (mask == 0) { GL.DepthMask(false); } GL.Disable(EnableCap.Lighting); { solid.sol_bill(ball_bill_M, t); } GL.Enable(EnableCap.Lighting); if (mask == 0) { GL.DepthMask(true); } if (test == 0) { GL.Enable(EnableCap.DepthTest); } } /* Draw the solid opaque and transparent geometry. */ solid.sol_draw(mask, test); } Video.MODELVIEW_PopMatrix(); if (solid_alpha < 1.0f) { GL.Disable(EnableCap.AlphaTest); } } }
/// <summary> /// Specifies the OpenGL alpha function to perform /// </summary> /// <param name="Comparison">The comparison to use</param> /// <param name="Value">The value to compare</param> private static void SetAlphaFunc(AlphaFunction Comparison, float Value) { AlphaTestEnabled = true; AlphaFuncComparison = Comparison; AlphaFuncValue = Value; GL.AlphaFunc(Comparison, Value); GL.Enable(EnableCap.AlphaTest); }
/// <summary>Specifies the OpenGL alpha function to perform</summary> /// <param name="Comparison">The comparison to use</param> /// <param name="Value">The value to compare</param> public void SetAlphaFunc(AlphaFunction Comparison, float Value) { alphaTestEnabled = true; alphaFuncComparison = Comparison; alphaFuncValue = Value; GL.Enable(EnableCap.AlphaTest); GL.AlphaFunc(Comparison, Value); }
public void Render() { float fFrameCount = (float)m_pRawDataProc.GetDepth(); GL.Clear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); GL.Enable(GL.GL_ALPHA_TEST); GL.AlphaFunc(GL.GL_GREATER, alphaThreshold); GL.Enable(GL.GL_BLEND); GL.BlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); GL.MatrixMode(GL.GL_TEXTURE); GL.LoadIdentity(); // Translate and make 0.5f as the center // (texture co ordinate is from 0 to 1. so center of rotation has to be 0.5f) GL.Translatef(0.5f, 0.5f, 0.5f); // A scaling applied to normalize the axis // (Usually the number of slices will be less so if this is not - // normalized then the z axis will look bulky) // Flipping of the y axis is done by giving a negative value in y axis. // This can be achieved either by changing the y co ordinates in - // texture mapping or by negative scaling of y axis GL.Scaled((float)m_pRawDataProc.GetWidth() / (float)m_pRawDataProc.GetWidth(), -1.0f * (float)m_pRawDataProc.GetWidth() / (float)(float)m_pRawDataProc.GetHeight(), (float)m_pRawDataProc.GetWidth() / (float)m_pRawDataProc.GetDepth()); GL.Scalef(wheel, wheel, wheel); // Apply the user provided transformations GL.MultMatrixd(m_pTransformMgr.GetMatrix()); GL.Translatef(-0.5f, -0.5f, -0.5f); GL.Enable(GL.GL_TEXTURE_3D); GL.BindTexture(GL.GL_TEXTURE_3D, m_pRawDataProc.GetTexture3D()); for (float fIndx = negativeZ; fIndx <= positiveZ; fIndx += 0.01f) { GL.Begin(GL.GL_QUADS); GL.TexCoord3f(0.0f, 0.0f, ((float)fIndx + 1.0f) / 2.0f); GL.Vertex3f(-dOrthoSize, -dOrthoSize, fIndx); GL.TexCoord3f(1.0f, 0.0f, ((float)fIndx + 1.0f) / 2.0f); GL.Vertex3f(dOrthoSize, -dOrthoSize, fIndx); GL.TexCoord3f(1.0f, 1.0f, ((float)fIndx + 1.0f) / 2.0f); GL.Vertex3f(dOrthoSize, dOrthoSize, fIndx); GL.TexCoord3f(0.0f, 1.0f, ((float)fIndx + 1.0f) / 2.0f); GL.Vertex3f(-dOrthoSize, dOrthoSize, fIndx); GL.End(); } GL.BindTexture(GL.GL_TEXTURE_3D, 0); }
public void RenderBillboard(float x, float y, float z, float size) { BillboardBegin(texture, x, y, z, size); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.Enable(EnableCap.AlphaTest); GL.AlphaFunc(AlphaFunction.Greater, AlphaMin); vbo.Render(); BillboardEnd(); }
void window_Load(object sender, EventArgs e) { GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Lequal); GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.AlphaTest); GL.AlphaFunc(AlphaFunction.Gequal, 0.5f); }
public static void LoadDefaultBlending() { GL.Enable(EnableCap.Blend); GL.Enable(EnableCap.AlphaTest); GL.AlphaFunc(AlphaFunction.Always, 0f); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); GL.BlendEquation(BlendEquationMode.FuncAdd); GL.Disable(EnableCap.ColorLogicOp); GL.LogicOp(LogicOp.Noop); }
private void OnRender() { if (LayoutFile == null) { return; } GL.Viewport(0, 0, glControl1.Width, glControl1.Height); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); if (UseOrtho) { GL.Ortho(-(glControl1.Width / 2.0f), glControl1.Width / 2.0f, glControl1.Height / 2.0f, -(glControl1.Height / 2.0f), -10000, 10000); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); } else { var cameraPosition = new Vector3(Camera.Position.X, Camera.Position.Y, -(Camera.Zoom * 500)); var perspectiveMatrix = Matrix4.CreateTranslation(cameraPosition) * Matrix4.CreatePerspectiveFieldOfView(1.3f, glControl1.Width / (float)glControl1.Height, 0.01f, 100000); GL.LoadMatrix(ref perspectiveMatrix); GL.MatrixMode(MatrixMode.Modelview); } GL.ClearColor(BackgroundColor); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Enable(EnableCap.AlphaTest); GL.AlphaFunc(AlphaFunction.Gequal, 0.1f); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); GL.Enable(EnableCap.ColorMaterial); GL.Enable(EnableCap.Texture2D); GL.BindTexture(TextureTarget.Texture2D, 0); if (UseOrtho) { GL.PushMatrix(); GL.Scale(1 * Camera.Zoom, -1 * Camera.Zoom, 1); GL.Translate(Camera.Position.X, Camera.Position.Y, 0); } DrawRootPane(LayoutFile.RootPane); DrawGrid(); DrawXyLines(); RenderPanes(LayoutFile.RootPane, true, 255, false); if (UseOrtho) { GL.PopMatrix(); } glControl1.SwapBuffers(); }
public Texture(string filename) { // create a texture id textureId = GL.GenTexture(); // bind this new texture id BindTexture(); // find base path var dir = new DirectoryInfo(Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().Location)); while (dir.Name != "bin") { dir = dir.Parent; } dir = dir.Parent; // load image file var path = Path.Combine(dir.ToString(), filename); if (!File.Exists(path)) { throw new FileNotFoundException($"Error: The file \"{path}\" does not exist."); } Bitmap image = new Bitmap(path); BitmapData data = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); // attach it to OpenGL context GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0); image.UnlockBits(data); // set texture properties, filters, blending functions, etc. GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Lequal); GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.AlphaTest); GL.AlphaFunc(AlphaFunction.Gequal, 0.5f); // unbind the texture UnbindTexture(); }
public void SetAlphaTest(bool enable, float reference, CompareOp op) { if (!enable) { GL.Disable(EnableCap.AlphaTest); return; } GL.AlphaFunc((AlphaFunction)op.Convert(), reference); GL.Enable(EnableCap.AlphaTest); }