public void Render(List <GUITexture> guiList) { if (guiList == null || guiList.Count > 0 == false) { return; } this.shader.Start(); Gl.BindVertexArray(this.quadModel.VaoID); Gl.EnableVertexAttribArray(0);// Position Gl.Enable(EnableCap.Blend); Gl.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); Gl.Disable(EnableCap.DepthTest); for (int i = 0; i < guiList.Count; i++) { Gl.ActiveTexture(TextureUnit.Texture0); Gl.BindTexture(TextureTarget.Texture2d, guiList[i].TextureID); Matrix4x4f transformationMatrix = Maths.CreateTransformationMatrix(guiList[i].Position, guiList[i].Scale); this.shader.LoadTransformationMatrix(transformationMatrix); Gl.DrawArrays(PrimitiveType.TriangleStrip, 0, this.quadModel.VertexCount); } Gl.Enable(EnableCap.DepthTest); Gl.Disable(EnableCap.Blend); Gl.DisableVertexAttribArray(0); Gl.BindVertexArray(0); this.shader.Stop(); }
private void PrepareRender(List <Light> lightList, Camera camera, float frameTimeSec) { this.shader.Start(); this.shader.LoadViewMatrix(camera); this.shader.LoadShineVariables(this.shineDamper, this.reflectivity); this.shader.LoadLights(lightList); this.moveFactor += WAVE_SPEED * frameTimeSec; this.moveFactor %= 1; this.shader.LoadMoveFactor(this.moveFactor); Gl.BindVertexArray(quad.VaoID); Gl.EnableVertexAttribArray(0); Gl.ActiveTexture(TextureUnit.Texture0); Gl.BindTexture(TextureTarget.Texture2d, this.fbos.ReflectionTexture); Gl.ActiveTexture(TextureUnit.Texture1); Gl.BindTexture(TextureTarget.Texture2d, this.fbos.RefractionTexture); Gl.ActiveTexture(TextureUnit.Texture2); Gl.BindTexture(TextureTarget.Texture2d, this.dudvTexture); Gl.ActiveTexture(TextureUnit.Texture3); Gl.BindTexture(TextureTarget.Texture2d, this.normalMap); Gl.ActiveTexture(TextureUnit.Texture4); Gl.BindTexture(TextureTarget.Texture2d, this.fbos.RefractionDepthTexture); Gl.Enable(EnableCap.Blend); Gl.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); }
private void ApplyStateCore(GraphicsContext ctx, ShaderProgram program, BlendState currentState) { if (Enabled) { // Enable blending if (currentState.Enabled == false) { Gl.Enable(EnableCap.Blend); } // Set blending equation if (ctx.Extensions.BlendMinmax_EXT) { if (EquationSeparated) { if (currentState.RgbEquation != RgbEquation || currentState.AlphaEquation != AlphaEquation) { Gl.BlendEquationSeparate(RgbEquation, AlphaEquation); } } else { if (currentState.RgbEquation != RgbEquation) { Gl.BlendEquation(RgbEquation); } } } // Set blending function if (FunctionSeparated) { if (currentState._RgbSrcFactor != _RgbSrcFactor || currentState._RgbDstFactor != _RgbDstFactor || currentState._AlphaSrcFactor != _AlphaSrcFactor || currentState._AlphaDstFactor != _AlphaDstFactor) { Gl.BlendFuncSeparate(_RgbSrcFactor, _RgbDstFactor, _AlphaSrcFactor, _AlphaDstFactor); } } else { if (currentState._RgbSrcFactor != _RgbSrcFactor || currentState._RgbDstFactor != _RgbDstFactor) { Gl.BlendFunc(_RgbSrcFactor, _RgbDstFactor); } } // Set blend color, if required if (RequiresConstColor(_RgbSrcFactor) || RequiresConstColor(_AlphaSrcFactor) || RequiresConstColor(_RgbDstFactor) || RequiresConstColor(_AlphaDstFactor)) { Gl.BlendColor(_BlendColor.r, _BlendColor.g, _BlendColor.b, _BlendColor.a); } } else { // Disable blending if (currentState.Enabled == true) { Gl.Disable(EnableCap.Blend); } } }
static void Main(string[] args) { Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH); Glut.glutInitWindowSize(width, height); Glut.glutCreateWindow("OpenGL Tutorial"); Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(OnDisplay); Glut.glutKeyboardFunc(OnKeyboardDown); Glut.glutKeyboardUpFunc(OnKeyboardUp); Glut.glutCloseFunc(OnClose); Glut.glutReshapeFunc(OnReshape); // enable blending and set to accumulate the star colors Gl.Disable(EnableCap.DepthTest); Gl.Enable(EnableCap.Blend); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.One); // create our shader program program = new ShaderProgram(VertexShader, FragmentShader); // set up the projection and view matrix program.Use(); program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f)); program["view_matrix"].SetValue(Matrix4.LookAt(new Vector3(0, 0, 20), Vector3.Zero, new Vector3(0, 1, 0))); // load the star texture starTexture = new Texture("star.bmp"); // each star is simply a quad star = new VBO <Vector3>(new Vector3[] { new Vector3(-1, -1, 0), new Vector3(1, -1, 0), new Vector3(1, 1, 0), new Vector3(-1, 1, 0) }); starUV = new VBO <Vector2>(new Vector2[] { new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1) }); starQuads = new VBO <int>(new int[] { 0, 1, 2, 0, 2, 3 }, BufferTarget.ElementArrayBuffer); // create 50 stars for this tutorial int numStars = 50; for (int i = 0; i < numStars; i++) { stars.Add(new Star(0, (float)i / numStars * 4f, new Vector3((float)generator.NextDouble(), (float)generator.NextDouble(), (float)generator.NextDouble()))); } font = new BMFont("font24.fnt", "font24.png"); fontProgram = new ShaderProgram(BMFont.FontVertexSource, BMFont.FontFragmentSource); fontProgram.Use(); fontProgram["ortho_matrix"].SetValue(Matrix4.CreateOrthographic(width, height, 0, 1000)); fontProgram["color"].SetValue(new Vector3(1, 1, 1)); information = font.CreateString(fontProgram, "OpenGL C# Tutorial 10"); watch = System.Diagnostics.Stopwatch.StartNew(); Glut.glutMainLoop(); }
public void ContextCreated() { Gl.Enable(EnableCap.DepthTest); Gl.Enable(EnableCap.Blend); Gl.Enable(EnableCap.CullFace); Gl.Enable(EnableCap.FramebufferSrgb); Gl.Enable((EnableCap)Gl.TEXTURE_CUBE_MAP_SEAMLESS); Gl.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); }
static void Main() { Window.CreateWindow("OpenGL UI: Example 7", 1280, 720); // add a reshape callback to update the UI Window.OnReshapeCallbacks.Add(() => OpenGL.UI.UserInterface.OnResize(Window.Width, Window.Height)); // add a close callback to make sure we dispose of everything properly Window.OnCloseCallbacks.Add(OnClose); // enable depth testing to ensure correct z-ordering of our fragments Gl.Enable(EnableCap.DepthTest); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); // initialize the user interface OpenGL.UI.UserInterface.InitUI(Window.Width, Window.Height); // load a texture that we'll use for the scroll bar of the textbox scrollTexture = new Texture("data/scrollBar.png"); // create a textbox OpenGL.UI.TextBox textBox = new OpenGL.UI.TextBox(OpenGL.UI.BMFont.LoadFont("fonts/font16.fnt"), scrollTexture); textBox.RelativeTo = OpenGL.UI.Corner.Center; textBox.Size = new Point(400, 200); textBox.BackgroundColor = new Vector4(0.3f, 0.3f, 0.3f, 1.0f); // put a bunch of text into the textbox textBox.WriteLine("Hello!"); textBox.WriteLine("This is a textbox, and it supports automatic word wrapping!"); textBox.WriteLine(new Vector3(0.5f, 0.7f, 1.0f), "It also supports colors!"); textBox.Write("It even supports "); textBox.Write(new Vector3(1, 0, 0), "multiple "); textBox.Write(new Vector3(0, 1, 0), "colors "); textBox.Write(new Vector3(0, 0, 1), "on "); textBox.WriteLine("the same line!"); textBox.WriteLine("It also supports a scroll bar and the ability to scroll through lots of text!"); textBox.WriteLine("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis eget vehicula orci. Nulla nibh nulla, suscipit non neque sed, placerat efficitur velit. Sed convallis gravida tincidunt. Praesent vehicula nibh leo, at consequat nisi condimentum ullamcorper. Vivamus pulvinar accumsan maximus. Integer luctus elit porttitor nisi sollicitudin, eget porttitor odio tincidunt. Sed elit justo, suscipit non dui ut, eleifend euismod nibh. Nullam ac fermentum nisl. In convallis id leo sit amet eleifend. Suspendisse eu ligula pulvinar ex facilisis cursus ac ac velit. In ut turpis nec neque vehicula eleifend. Morbi in tempus est. Vivamus nisi nunc, pharetra quis scelerisque ut, tempor id dui."); textBox.AllowScrollBar = true; textBox.CurrentLine = 0; // add the textbox to the user interface OpenGL.UI.UserInterface.AddElement(textBox); // subscribe the escape event using the OpenGL.UI class library Input.Subscribe((char)27, Window.OnClose); // make sure to set up mouse event handlers for the window Window.OnMouseCallbacks.Add(OpenGL.UI.UserInterface.OnMouseClick); Window.OnMouseMoveCallbacks.Add(OpenGL.UI.UserInterface.OnMouseMove); while (Window.Open) { Window.HandleEvents(); OnRenderFrame(); } }
/// <summary> /// Draw all the entities that has a render component /// </summary> internal override void Draw() { Flush(); UpdateData(); if (renderableComponents.Length == 0) { return; } TextureManager.Instance.BindTextureArrayToShader("textureArray", Shader.BasicShader); TextureManager.Instance.BindTextureArray(); Gl.Enable(EnableCap.Blend); Gl.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); uint currentIndicieCount = 0; for (int i = 0; i < renderableComponents.Length; i++) { Shader.BasicShader.SetUniformM4("modelView", renderableComponents[i].Entity.ModelView); uint quadsCount = (uint)(renderableComponents[i].Vertices.Length / 4); if (!renderableComponents[i].ComponentEnabled) { currentIndicieCount += quadsCount * 6 * sizeof(int); continue; } if (!renderableComponents[i].Entity.EntityEnabled) { currentIndicieCount += quadsCount * 6 * sizeof(int); continue; } // Draw Shader.BasicShader.Enable(); vao.Bind(); ibo.Bind(); //Gl.DrawElements(PrimitiveType.Triangles, 6, DrawElementsType.UnsignedInt, (IntPtr)((i * (6 * quadsCount)) * sizeof(int))); for (int j = 0; j < quadsCount; j++) { Gl.DrawElements(PrimitiveType.Triangles, 6, DrawElementsType.UnsignedInt, (IntPtr)(currentIndicieCount + (j * 6 * sizeof(int)))); } ibo.Unbind(); vao.Unbind(); Shader.BasicShader.Disable(); currentIndicieCount += quadsCount * 6 * sizeof(int); } TextureManager.Instance.UnbindTextureArray(); }
/// <summary> /// Set ShaderProgram state. /// </summary> /// <param name="ctx"> /// A <see cref="GraphicsContext"/> which has defined the shader program <paramref name="sProgram"/>. /// </param> /// <param name="sProgram"> /// The <see cref="ShaderProgram"/> which has the state set. /// </param> public override void ApplyState(GraphicsContext ctx, ShaderProgram sProgram) { if (ctx == null) { throw new ArgumentNullException("ctx"); } BlendState currentState = null; // (BlendState)ctx.CurrentState[StateId]; if (Enabled) { // Enable blending if (currentState == null || !currentState.Enabled) { Gl.Enable(EnableCap.Blend); } // Set blending equation if (ctx.Caps.GlExtensions.BlendMinmax_EXT) { if (EquationSeparated) { Gl.BlendEquationSeparate(RgbEquation, AlphaEquation); } else { Gl.BlendEquation((int)RgbEquation); } } // Set blending function if (FunctionSeparated) { Gl.BlendFuncSeparate((int)mRgbSrcFactor, (int)mRgbDstFactor, (int)mAlphaSrcFactor, (int)mAlphaDstFactor); } else { Gl.BlendFunc(mRgbSrcFactor, mRgbDstFactor); } // Set blend color, if required if (RequiresConstColor(mRgbSrcFactor) || RequiresConstColor(mAlphaSrcFactor) || RequiresConstColor(mRgbDstFactor) || RequiresConstColor(mAlphaDstFactor)) { Gl.BlendColor(mBlendColor.Red, mBlendColor.Green, mBlendColor.Blue, mBlendColor.Alpha); } } else { // Disable blending if (currentState == null || currentState.Enabled) { Gl.Disable(EnableCap.Blend); } } }
public override void Paint(Rectangle visibleTiles, MapLocation mouseLocationOnMap) { if (_toolStep > ToolStep.SetOrigin) { Gl.Begin(PrimitiveType.Triangles); RenderQuad(Owner.TextureMap[MapTileVisual.Origin], Owner.GetMapLocationOnClient(_origin), new Color4() { A = 1.0f, R = 1.0f, G = 1.0F, B = 1.0F }); if (_toolStep > ToolStep.SetDestination) { RenderQuad(Owner.TextureMap[MapTileVisual.Destination], Owner.GetMapLocationOnClient(_destination), new Color4() { A = 1.0f, R = 1.0f, G = 1.0F, B = 1.0F }); } Gl.End(); if (_toolStep == ToolStep.Pathfind && _computedPath?.Path?.Length > 0) { Gl.Disable(EnableCap.Texture2d); Gl.Begin(PrimitiveType.Lines); Gl.Color3(0.0f, 0.0f, 1.0f); var start = Owner.GetMapLocationOnClient(_computedPath.Path[0]); for (int i = 1; i < _computedPath.Path.Length; i++) { var end = Owner.GetMapLocationOnClient(_computedPath.Path[i]); Gl.Vertex2(start.X + start.Width / 2, start.Y + start.Height / 2); Gl.Vertex2(end.X + end.Width / 2, end.Y + end.Height / 2); start = end; } Gl.End(); Gl.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); Gl.Enable(EnableCap.Blend); Gl.Begin(PrimitiveType.Triangles); foreach (var coloredTile in _computedPath.ColoredTiles) { RenderQuad(Owner.TextureMap[MapTileVisual.White], Owner.GetMapLocationOnClient(coloredTile), new Color4() { A = 0.2f, R = 0.0f, G = 0.0F, B = 1.0F }); } Gl.End(); } } }
static void Main(string[] args) { Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH | Glut.GLUT_ALPHA | Glut.GLUT_STENCIL | Glut.GLUT_MULTISAMPLE); Glut.glutInitWindowSize(width, height); Glut.glutCreateWindow("OpenGL Tutorial"); Gl.Enable(EnableCap.DepthTest); Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(OnDisplay); Glut.glutKeyboardFunc(OnKeyboardDown); Glut.glutKeyboardUpFunc(OnKeyboardUp); Glut.glutCloseFunc(OnClose); Glut.glutReshapeFunc(OnReshape); // add our mouse callbacks for this tutorial Glut.glutMouseFunc(OnMouse); Glut.glutMotionFunc(OnMove); Gl.Enable(EnableCap.Blend); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); // create our shader program program = new ShaderProgram(VertexShader, FragmentShader); // create our camera camera = new Camera(new Vector3(0, 0, 50), Quaternion.Identity); camera.SetDirection(new Vector3(0, 0, -1)); // set up the projection and view matrix program.Use(); program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f)); program["model_matrix"].SetValue(Matrix4.Identity); objectFile = new ObjLoader("enterprise/enterprise.obj", program); // load the bitmap font for this tutorial font = new BMFont("font24.fnt", "font24.png"); fontProgram = new ShaderProgram(BMFont.FontVertexSource, BMFont.FontFragmentSource); fontProgram.Use(); fontProgram["ortho_matrix"].SetValue(Matrix4.CreateOrthographic(width, height, 0, 1000)); fontProgram["color"].SetValue(new Vector3(1, 1, 1)); information = font.CreateString(fontProgram, "OpenGL C# Tutorial 16"); watch = System.Diagnostics.Stopwatch.StartNew(); Glut.glutMainLoop(); }
public virtual void Initialize(int width, int height) { //Setup opengl and window OpenGL.Platform.Window.CreateWindow("OpenGL", this.width, this.height, false); Gl.Enable(EnableCap.DepthTest); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); clock = new Clock(); //setup logging system Log.CreateLoggers(); }
static void Main() { Window.CreateWindow("OpenGL UI: Example 3", 1280, 720); // add a reshape callback to update the UI Window.OnReshapeCallbacks.Add(() => OpenGL.UI.UserInterface.OnResize(Window.Width, Window.Height)); // add a close callback to make sure we dispose of everything properly Window.OnCloseCallbacks.Add(OnClose); // enable depth testing to ensure correct z-ordering of our fragments Gl.Enable(EnableCap.DepthTest); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); // initialize the user interface OpenGL.UI.UserInterface.InitUI(Window.Width, Window.Height); // create some centered text OpenGL.UI.Text selectText = new OpenGL.UI.Text(OpenGL.UI.Text.FontSize._16pt, "Pick A Color:", OpenGL.UI.BMFont.Justification.Center); selectText.Position = new Point(0, 80); selectText.RelativeTo = OpenGL.UI.Corner.Center; // add the two text object to the UI OpenGL.UI.UserInterface.AddElement(selectText); // create the color picker itself OpenGL.UI.ColorGradient gradient = new OpenGL.UI.ColorGradient(); gradient.RelativeTo = OpenGL.UI.Corner.Center; gradient.Position = new Point(-20, 0); gradient.OnColorChange = (sender, e) => selectText.Color = gradient.Color; // and create a hue slider that can control the types of colors shown in the color picker OpenGL.UI.HueGradient hue = new OpenGL.UI.HueGradient(); hue.RelativeTo = OpenGL.UI.Corner.Center; hue.Position = new Point(80, 0); // add the color picker and its hue slider to the UI OpenGL.UI.UserInterface.AddElement(gradient); OpenGL.UI.UserInterface.AddElement(hue); // subscribe the escape event using the OpenGL.UI class library Input.Subscribe((char)27, Window.OnClose); // make sure to set up mouse event handlers for the window Window.OnMouseCallbacks.Add(OpenGL.UI.UserInterface.OnMouseClick); Window.OnMouseMoveCallbacks.Add(OpenGL.UI.UserInterface.OnMouseMove); while (true) { Window.HandleEvents(); OnRenderFrame(); } }
private void NativeWindow_ContextCreated(object sender, NativeWindowEventArgs e) { Gl.ReadBuffer(ReadBufferMode.Back); Gl.ClearColor(0.0f, 0.0f, 0.0f, 1.0f); Gl.Enable(EnableCap.Blend); Gl.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); Gl.LineWidth(2.5f); CreateResources(); }
private void ContextCreated(object sender, NativeWindowEventArgs e) { debugProc = GlDebugCallback; Gl.DebugMessageCallback(debugProc, null); Gl.Enable(EnableCap.DepthTest); Gl.Enable(EnableCap.Blend); Gl.Enable(EnableCap.CullFace); Gl.Enable(EnableCap.FramebufferSrgb); Gl.Enable((EnableCap)Gl.TEXTURE_CUBE_MAP_SEAMLESS); Gl.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); // imgui = new QuincyImGui(); scene = new Scene(); }
protected override void DrawElements() { Gl.Enable(EnableCap.DepthTest); // Enable blending Gl.Enable(EnableCap.Blend); Gl.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); Gl.PointSize(pointSize); Gl.BindVertexArray(vertexArrayObject); Gl.DrawArrays(PrimitiveType.Points, 0, Vertices.Length); }
public RendererCapabilities CreateContext(IntPtr window) { // OpenGL only allows for one thread per context, so if a context already exists it has to be cleaned up before trying to make a new one. if (ContextHandle != IntPtr.Zero) { SDL_GL_DeleteContext(ContextHandle); } else { Gl.Initialize(); } // Set OpenGL attributes. SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_RED_SIZE, 8); // Allocate 8 bits per pixel for the red color-channel. SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_GREEN_SIZE, 8); // Allocate 8 bits per pixel for the green color-channel. SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_BLUE_SIZE, 8); // Allocate 8 bits per pixel for the blue color-channel. SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_ALPHA_SIZE, 8); // Allocate 8 bits per pixel for the alpha channel. SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_BUFFER_SIZE, 32); // Therefore, one pixel in the screen buffer allocates 32 bits. SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_DEPTH_SIZE, 16); // Allocate a 16-bit depth buffer. SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_DOUBLEBUFFER, 1); // Enable double buffering. SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_CONTEXT_PROFILE_MASK, (int)SDL_GLprofile.SDL_GL_CONTEXT_PROFILE_CORE); SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_CONTEXT_MAJOR_VERSION, 3); // Set the specifications of the OpenGL context to 3.2 core. SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_CONTEXT_MINOR_VERSION, 2); // Create the context and bind it to the hwnd. ContextHandle = SDL_GL_CreateContext(window); SDL_GL_MakeCurrent(window, ContextHandle); // Disable V-Sync. SDL_GL_SetSwapInterval(0); // Setup an OpenGL debug context for easier debugging. Gl.Enable((EnableCap)Gl.DEBUG_OUTPUT); Gl.Enable((EnableCap)Gl.DEBUG_OUTPUT_SYNCHRONOUS); Gl.DebugMessageCallback(OpenGLMessageCallback, IntPtr.Zero); Gl.DebugMessageControl(DebugSource.DontCare, DebugType.DontCare, DebugSeverity.DebugSeverityNotification, 0, null, false); // Query the graphics driver for the capabilities of the GPU. RendererCapabilities caps = new RendererCapabilities(); Gl.GetInteger(GetPName.MaxTextureSize, out caps.MaxTextureSize); Gl.GetInteger(GetPName.MaxTextureImageUnits, out caps.NumTextureSlots); // Setup alpha blending and depth testing. Gl.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); Gl.CullFace(CullFaceMode.Back); Gl.Enable(EnableCap.Blend); Gl.Enable(EnableCap.DepthTest); return(caps); }
static void Main() { Window.CreateWindow("OpenGL UI: Example 5", 1280, 720); // add a reshape callback to update the UI Window.OnReshapeCallbacks.Add(() => OpenGL.UI.UserInterface.OnResize(Window.Width, Window.Height)); // add a close callback to make sure we dispose of everything properly Window.OnCloseCallbacks.Add(OnClose); // enable depth testing to ensure correct z-ordering of our fragments Gl.Enable(EnableCap.DepthTest); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); // initialize the user interface OpenGL.UI.UserInterface.InitUI(Window.Width, Window.Height); // create a slider with a specified texture sliderTexture = new Texture("data/slider.png"); OpenGL.UI.Slider slider = new OpenGL.UI.Slider(sliderTexture); slider.RelativeTo = OpenGL.UI.Corner.Center; slider.BackgroundColor = new Vector4(0.1f, 0.1f, 0.1f, 1f); slider.LockToSteps = true; // create some text that will change with the slider position OpenGL.UI.Text text = new OpenGL.UI.Text(OpenGL.UI.Text.FontSize._16pt, "Value: 0"); text.RelativeTo = OpenGL.UI.Corner.Center; text.Position = new Point(120, -text.TextSize.Y / 2); slider.OnValueChanged = (sender, e) => text.String = string.Format("Value: {0}", slider.Value); // add both the slider and text controls to the UI OpenGL.UI.UserInterface.AddElement(slider); OpenGL.UI.UserInterface.AddElement(text); // subscribe the escape event using the OpenGL.UI class library Input.Subscribe((char)27, Window.OnClose); // make sure to set up mouse event handlers for the window Window.OnMouseCallbacks.Add(OpenGL.UI.UserInterface.OnMouseClick); Window.OnMouseMoveCallbacks.Add(OpenGL.UI.UserInterface.OnMouseMove); while (Window.Open) { Window.HandleEvents(); OnRenderFrame(); } }
public static void Draw() { if (Model == null) { return; } Roller.Update(); if (ViewportIsDirty) { Gl.Viewport(0, 0, ViewportWidth, ViewportHeight); CameraDistance = CAMERA_DISTANCE_RATIO * Model.BoundingRadius; ViewportCanonicalScale = 2f / Math.Min(ViewportWidth, ViewportHeight); var s = (double)Model.BoundingRadius * ViewportCanonicalScale / 2; Gl.MatrixMode(MatrixMode.Projection); Gl.LoadIdentity(); Gl.Frustum(-ViewportWidth * s, ViewportWidth * s, -ViewportHeight * s, ViewportHeight * s, CameraDistance - Model.BoundingRadius, CameraDistance + Model.BoundingRadius); //Gl.Ortho(-ViewportWidth * s, ViewportWidth * s, -ViewportHeight * s, ViewportHeight * s, distance - MeshRadious, distance + MeshRadious); Gl.Translate(0f, 0f, -CameraDistance); } Gl.ClearColor(0.0f, 0.0f, 0.0f, 1.0f); Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); Gl.MatrixMode(MatrixMode.Modelview); Gl.LoadIdentity(); Gl.Disable(EnableCap.Normalize); Gl.Enable(EnableCap.Multisample); Gl.Disable(EnableCap.Blend); Gl.Disable(EnableCap.Dither); Gl.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); Gl.Enable(EnableCap.Lighting); Gl.Enable(EnableCap.Light0); Gl.Light(LightName.Light0, LightParameter.Ambient, new[] { 0.8f, 0.8f, 0.8f, 1.0f }); Gl.Light(LightName.Light0, LightParameter.Specular, new[] { 0.5f, 0.5f, 0.5f, 1.0f }); Gl.Light(LightName.Light0, LightParameter.Diffuse, new[] { 1.0f, 1.0f, 1.0f, 1.0f }); Gl.Light(LightName.Light0, LightParameter.Position, new[] { 0.3f, 0.5f, 1.0f, 0.0f }); Gl.MultMatrix(Roller.getMatrix().ToArray()); Model.Draw(); }
public OpenGLRenderer() { Gl.ClearColor(0.0f, 0.0f, 0.0f, 1.0f); Gl.ClearDepthf(1.0f); Gl.Enable(EnableCap.Multisample); Gl.Enable(EnableCap.DepthTest); Gl.DepthFunc(DepthFunction.Lequal); Gl.Enable(EnableCap.CullFace); Gl.CullFace(CullFaceMode.Back); Gl.Enable(EnableCap.Blend); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); }
// Init Window private void NativeWindow_ContextCreated(object sender, NativeWindowEventArgs e) { OpenGL.CoreUI.NativeWindow nativeWindow = (OpenGL.CoreUI.NativeWindow)sender; Gl.ReadBuffer(ReadBufferMode.Back); Gl.ClearColor(0.0f, 0.0f, 0.0f, 1.0f); Gl.Enable(EnableCap.Blend); Gl.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); Gl.Enable(EnableCap.LineSmooth); Gl.Hint(HintTarget.LineSmoothHint, HintMode.Nicest); viewer.init(zedCamera.GetCalibrationParameters().leftCam); }
private void RenderScene(object sender, GlControlEventArgs e) { if (!this.initialized) { if (this.BeforeRenderInitialize != null) { this.BeforeRenderInitialize(); } Gl.Initialize(); Gl.ShadeModel(ShadingModel.Flat); Gl.Disable(EnableCap.Lighting); Gl.Enable(EnableCap.DepthTest); Gl.DepthMask(true); Gl.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Fastest); Gl.Hint(HintTarget.PolygonSmoothHint, HintMode.Fastest); Gl.Hint(HintTarget.PointSmoothHint, HintMode.Fastest); Gl.Hint(HintTarget.LineSmoothHint, HintMode.Fastest); Gl.Hint(HintTarget.TextureCompressionHint, HintMode.Fastest); Gl.DepthFunc(DepthFunction.Lequal); Gl.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); Gl.Enable(EnableCap.Blend); if (this.AfterRenderInitialize != null) { this.AfterRenderInitialize(); } this.initialized = true; } #region Begin Render Gl.Viewport(0, 0, this.openGlControl.Width, this.openGlControl.Height); Gl.ClearColor(this.ClearColor.Rf, this.ClearColor.Gf, this.ClearColor.Bf, this.ClearColor.Af); Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); Gl.MatrixMode(MatrixMode.Projection); Gl.LoadIdentity(); Gl.Ortho(-1.0, 1.0, 1.0, -1.0, -1.0, 1.0); Gl.MatrixMode(MatrixMode.Modelview); Gl.LoadIdentity(); #endregion if (this.RenderFrame != null) { this.RenderFrame(); } this.renderPanel.SuspendLayout(); this.renderPanel.Image = this.CaptureScaledBitmap(this.renderPanel.Width, this.renderPanel.Height); this.renderPanel.ResumeLayout(); }
static void Main() { Window.CreateWindow("OpenGL UI: Example 6", 1280, 720); // add a reshape callback to update the UI Window.OnReshapeCallbacks.Add(() => OpenGL.UI.UserInterface.OnResize(Window.Width, Window.Height)); // add a close callback to make sure we dispose of everything properly Window.OnCloseCallbacks.Add(OnClose); // enable depth testing to ensure correct z-ordering of our fragments Gl.Enable(EnableCap.DepthTest); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); // initialize the user interface OpenGL.UI.UserInterface.InitUI(Window.Width, Window.Height); // create a checkbox with a specified texture checkBoxTexture = new Texture("data/checkBox.png"); checkBoxCheckedTexture = new Texture("data/checkBoxChecked.png"); OpenGL.UI.CheckBox checkbox1 = new OpenGL.UI.CheckBox(checkBoxTexture, checkBoxCheckedTexture, OpenGL.UI.BMFont.LoadFont("fonts/font16.fnt"), "Check Me!"); checkbox1.RelativeTo = OpenGL.UI.Corner.Center; checkbox1.Position = new Point(-50, 12); checkbox1.OnCheckedChanged = (sender, e) => checkbox1.Text = (checkbox1.Checked ? "Thanks!" : "Check Me!"); OpenGL.UI.CheckBox checkbox2 = new OpenGL.UI.CheckBox(checkBoxTexture, checkBoxCheckedTexture, OpenGL.UI.BMFont.LoadFont("fonts/font16.fnt"), "Check Me Too!"); checkbox2.RelativeTo = OpenGL.UI.Corner.Center; checkbox2.Position = new Point(-50, -12); checkbox2.OnCheckedChanged = (sender, e) => checkbox2.Text = (checkbox2.Checked ? "Thanks!" : "Check Me Too!"); // add both checkbox controls to the user interface OpenGL.UI.UserInterface.AddElement(checkbox1); OpenGL.UI.UserInterface.AddElement(checkbox2); // subscribe the escape event using the OpenGL.UI class library Input.Subscribe((char)27, Window.OnClose); // make sure to set up mouse event handlers for the window Window.OnMouseCallbacks.Add(OpenGL.UI.UserInterface.OnMouseClick); Window.OnMouseMoveCallbacks.Add(OpenGL.UI.UserInterface.OnMouseMove); while (true) { Window.HandleEvents(); OnRenderFrame(); } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); VSync = VSyncMode.Off; CursorVisible = false; Gl.Enable(EnableCap.Multisample); Gl.Enable(EnableCap.DepthTest); Gl.Enable(EnableCap.CullFace); Gl.Enable(EnableCap.Blend); Gl.CullFace(CullFaceMode.Back); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); Console.WriteLine(Math.Min(4f, Gl.GetFloat(GetPName.MaxTextureMaxAnisotropyExt))); game = new Game(); game.SetProjection(Width, Height); }
private void GlControl1_ContextCreated(object sender, GlControlEventArgs e) { game = new Game.Game(); game.World.DebugEvents.EntityAdded += DebugEvents_EntityAdded; game.World.DebugEvents.EntityRemoved += DebugEvents_EntityRemoved; game.Init(); renderer = game.World.GetDependency <Renderer>(); keyBinds = GetKeyBindings(); stopwatch = new Stopwatch(); timescaleInput.ValidatingType = typeof(float); timestepInput.ValidatingType = typeof(float); Gl.Enable(EnableCap.Blend); Gl.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); previousTime = stopwatch.Elapsed.TotalSeconds; }
private void RenderControl_ContextCreated(object sender, GlControlEventArgs e) { GlControl glControl = (GlControl)sender; // Here you can allocate resources or initialize state Gl.MatrixMode(MatrixMode.Projection); Gl.LoadIdentity(); Gl.Ortho(OrthoLeft, OrthoRight, OrthoBottom, OrthoTop, -0.1, 10.0); Gl.Enable(EnableCap.Texture2d); Gl.Enable(EnableCap.Blend); Gl.Enable(EnableCap.DepthTest); //Set up Z Depth tests for drawing pixels Gl.DepthFunc(DepthFunction.Lequal); //Only draw something new if its z value is closer to the 'camera' Gl.DepthMask(true); Gl.ClearDepth(10f); Gl.ClearColor(36 / 255f, 71 / 255f, 143 / 255f, 1f); Gl.Enable(EnableCap.AlphaTest); //Set up Alpha tests for drawing pixels Gl.AlphaFunc(AlphaFunction.Greater, .05f); //Don't draw transparent pixels on polygons Gl.Enable(EnableCap.ScissorTest); Gl.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); Gl.EnableClientState(EnableCap.VertexArray); Gl.EnableClientState(EnableCap.TextureCoordArray); contextCreated = true; Console.Console.ConsoleSetup(); WorldData.WorldStartup(); Screen.ScreenStartup(); MaximizeBox = false; if (Save.SaveData.GameSettings.fullScreen) { FormBorderStyle = FormBorderStyle.None; WindowState = FormWindowState.Maximized; } if (Save.SaveData.GameSettings.VSync) { Wgl.SwapIntervalEXT(-1); //Swap Interval (V-Sync Enabled at 1 or -1) } else { Wgl.SwapIntervalEXT(0); } ResizeWindow(Save.SaveData.GameSettings.windowx, Save.SaveData.GameSettings.windowy); ResizeE(sender, e); LogicUtils.Logic.LogicStart(); }
static void Main() { Window.CreateWindow("OpenGL UI: Example 9", 1280, 720); // add a reshape callback to update the UI Window.OnReshapeCallbacks.Add(() => OpenGL.UI.UserInterface.OnResize(Window.Width, Window.Height)); // add a close callback to make sure we dispose of everything properly Window.OnCloseCallbacks.Add(OnClose); // enable depth testing to ensure correct z-ordering of our fragments Gl.Enable(EnableCap.DepthTest); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); // initialize the user interface OpenGL.UI.UserInterface.InitUI(Window.Width, Window.Height); OpenGL.UI.Text text = new OpenGL.UI.Text(OpenGL.UI.Text.FontSize._16pt, "Type Something:"); text.RelativeTo = OpenGL.UI.Corner.Center; text.Position = new Point(-260, -10); // create a text input control OpenGL.UI.TextInput textInput = new OpenGL.UI.TextInput(OpenGL.UI.BMFont.LoadFont("fonts/font16.fnt")); textInput.Size = new Point(300, 20); textInput.Position = new Point(50, 0); textInput.RelativeTo = OpenGL.UI.Corner.Center; textInput.BackgroundColor = new Vector4(0.3f, 0.3f, 0.3f, 1.0f); // add the text input control to the user interface OpenGL.UI.UserInterface.AddElement(textInput); OpenGL.UI.UserInterface.AddElement(text); // subscribe the escape event using the OpenGL.UI class library Input.Subscribe((char)27, Window.OnClose); // make sure to set up mouse event handlers for the window Window.OnMouseCallbacks.Add(OpenGL.UI.UserInterface.OnMouseClick); Window.OnMouseMoveCallbacks.Add(OpenGL.UI.UserInterface.OnMouseMove); while (Window.Open) { Window.HandleEvents(); OnRenderFrame(); } }
private static void RenderInstance(GuiModel model, Vector2 pos, Vector4 colour) { ShaderProgram shader = Gui.shader; Gl.Enable(EnableCap.Blend); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); shader["position"].SetValue(pos); shader["size"].SetValue(model.size); shader["colour"].SetValue(colour); Gl.BindVertexArray(model.vao.ID); Gl.BindTexture(model.texture.TextureTarget, model.texture.TextureID); Gl.DrawElements(model.drawmode, model.vao.count, DrawElementsType.UnsignedInt, IntPtr.Zero); Gl.BindTexture(model.texture.TextureTarget, 0); Gl.BindVertexArray(0); Gl.Disable(EnableCap.Blend); }
private static void InitializeMain() { Time.Initialize(); Camera.screenWidth = screenWidth; Camera.screenHeight = screenHeight; Window.CreateWindow("OpenGL Rendering Demo", screenWidth, screenHeight); // add a reshape callback to update the UI Window.OnReshapeCallbacks.Add(OnResize); // add a close callback to make sure we dispose of everythng properly Window.OnCloseCallbacks.Add(OnClose); // Enable depth testing to ensure correct z-ordering of our fragments Gl.Enable(EnableCap.DepthTest); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); Gl.PolygonMode(MaterialFace.Front, PolygonMode.Fill); }
public void Init() { //Open GL init #region Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH); Glut.glutInitWindowSize(width, height); Glut.glutCreateWindow("Maraca craft"); Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(OnDisplay); Glut.glutCloseFunc(OnClose); Glut.glutKeyboardFunc(OnKeyboardDown); Gl.ClearColor(0, 0, 0, 1); //Alpha enabled Gl.Enable(EnableCap.DepthTest); Gl.Enable(EnableCap.Blend); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); #endregion //Load shader program = new ShaderProgram(VertexShader, FragmentShader); //Create perspective program.Use(); program["projection_matrix"].SetValue( Matrix4.CreatePerspectiveFieldOfView(0.95f, (float)width / height, 0.1f, 1000f)); Vector3 camPos = new Vector3(0, 0, 0); //-5 3 -5 program["view_matrix"].SetValue( Matrix4.CreateTranslation(new Vector3(0, 0, 0)) * Matrix4.LookAt(new Vector3(0, 0, -1), camPos, new Vector3(0, 1, 0))); player = new Player(0, 0, 0); CreateModels(); Glut.glutMainLoop(); }
static void Main() { Window.CreateWindow("OpenGL UI: Example 1", 1280, 720); // add a reshape callback to update the UI Window.OnReshapeCallbacks.Add(() => OpenGL.UI.UserInterface.OnResize(Window.Width, Window.Height)); // add a close callback to make sure we dispose of everything properly Window.OnCloseCallbacks.Add(OnClose); // enable depth testing to ensure correct z-ordering of our fragments Gl.Enable(EnableCap.DepthTest); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); // initialize the user interface OpenGL.UI.UserInterface.InitUI(Window.Width, Window.Height); // create some centered text OpenGL.UI.Text welcome = new OpenGL.UI.Text(OpenGL.UI.Text.FontSize._24pt, "Welcome to OpenGL", OpenGL.UI.BMFont.Justification.Center); welcome.RelativeTo = OpenGL.UI.Corner.Center; // create some colored text OpenGL.UI.Text coloredText = new OpenGL.UI.Text(OpenGL.UI.Text.FontSize._24pt, "using C#", OpenGL.UI.BMFont.Justification.Center); coloredText.Position = new Point(0, -30); coloredText.Color = new Vector3(0.2f, 0.3f, 1f); coloredText.RelativeTo = OpenGL.UI.Corner.Center; // add the two text object to the UI OpenGL.UI.UserInterface.AddElement(welcome); OpenGL.UI.UserInterface.AddElement(coloredText); // subscribe the escape event using the OpenGL.UI class library Input.Subscribe((char)27, Window.OnClose); // make sure to set up mouse event handlers for the window Window.OnMouseCallbacks.Add(OpenGL.UI.UserInterface.OnMouseClick); Window.OnMouseMoveCallbacks.Add(OpenGL.UI.UserInterface.OnMouseMove); while (Window.Open) { Window.HandleEvents(); OnRenderFrame(); } }