public void Load() { _squareVertices = new[] { //Front Face -Size, -Size, Size, Size, -Size, Size, Size, Size, Size, -Size, Size, Size, //Back Face -Size, -Size, -Size, -Size, Size, -Size, Size, Size, -Size, Size, -Size, -Size, //Top Face -Size, Size, -Size, -Size, Size, Size, Size, Size, Size, Size, Size, -Size, //Bottom Face -Size, -Size, -Size, Size, -Size, -Size, Size, -Size, Size, -Size, -Size, Size, //Right Face Size, -Size, -Size, Size, Size, -Size, Size, Size, Size, Size, -Size, Size, //Left Face -Size, -Size, -Size, -Size, -Size, Size, -Size, Size, Size, -Size, Size, -Size }; _shader = new ShaderProgram(); using (var sr = new StreamReader("Shaders/Voxel.Vert")) { _shader.AddShader(ShaderType.VertexShader, sr.ReadToEnd()); } using (var sr = new StreamReader("Shaders/VoxelGreen.Frag")) { _shader.AddShader(ShaderType.FragmentShader, sr.ReadToEnd()); } GL.BindAttribLocation(_shader.Program, 0, "position"); GL.BindAttribLocation(_shader.Program, 1, "instance_position"); GL.BindAttribLocation(_shader.Program, 2, "instance_rotation"); _shader.Link(); GL.GenVertexArrays(1, out _squareVao); GL.GenBuffers(1, out _squareVbo); GL.BindVertexArray(_squareVao); GL.BindBuffer(BufferTarget.ArrayBuffer, _squareVbo); GL.EnableVertexAttribArray(0); GL.EnableVertexAttribArray(1); GL.EnableVertexAttribArray(2); GL.Arb.VertexAttribDivisor(1, 1); GL.Arb.VertexAttribDivisor(2, 1); Loaded = true; }
protected override void OnLoad(EventArgs e) { Console.WriteLine("OnLoad"); VSync = VSyncMode.Off; CreateProjection(); program = new ShaderProgram(); program.AddShader(ShaderType.VertexShader, ShaderProgram.GetDefaultColorVertexShader()); program.AddShader(ShaderType.FragmentShader, ShaderProgram.GetDefaultColorFragmentShader()); program.Link(); textureProgram = new ShaderProgram(); textureProgram.AddShader(ShaderType.VertexShader, ShaderProgram.GetDefaultTextureVertexShader()); textureProgram.AddShader(ShaderType.FragmentShader, ShaderProgram.GetDefaultTextureFragmentShader()); textureProgram.Link(); Renderable renderable = new ObjectRenderer(RenderableFactory.CreateSolidCube(1, Color.Red), program.Id); Renderable renderableTextured = new ObjectRenderer(RenderableFactory.CreateTexturedCube(1, 1, 1), textureProgram.Id, "default.png"); //renderables.Add("renderable", renderable); renderables.Add("renderable2", renderableTextured); CursorVisible = true; GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); GL.PatchParameter(PatchParameterInt.PatchVertices, 3); GL.PointSize(3); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.CullFace); base.OnLoad(e); }
static int createShader(string name) { var program = new ShaderProgram(); program.AddShader(ShaderType.VertexShader, FileExplorer.Shaders + name + ".vert"); program.AddShader(ShaderType.FragmentShader, FileExplorer.Shaders + name + ".frag"); program.Link(); programs[programCount++] = program; return(program.ID); }
private void LoadShaderPrograms() { var textureProgram = new ShaderProgram(); textureProgram.AddShader(ShaderType.VertexShader, @"..\..\..\Shaders\Texture\simplePipeTexVert.c"); textureProgram.AddShader(ShaderType.FragmentShader, @"..\..\..\Shaders\Texture\simplePipeTexFrag.c"); textureProgram.Link(); ShaderProgramList.Add("textureProgram", textureProgram); var solidProgram = new ShaderProgram(); solidProgram.AddShader(ShaderType.VertexShader, @"..\..\..\Shaders\SolidColor\simplePipeVert.c"); solidProgram.AddShader(ShaderType.FragmentShader, @"..\..\..\Shaders\SolidColor\simplePipeFrag.c"); solidProgram.Link(); ShaderProgramList.Add("solidProgram", solidProgram); }
protected override void OnLoad(EventArgs e) { Debug.WriteLine("OnLoad"); VSync = VSyncMode.Off; CreateProjection(); _solidProgram = new ShaderProgram(); _solidProgram.AddShader(ShaderType.VertexShader, @"Components\Shaders\Solid\vertexShader.vert"); _solidProgram.AddShader(ShaderType.FragmentShader, @"Components\Shaders\Solid\fragmentShader.frag"); _solidProgram.Link(); render2 = new RenderObject(OpenTKPrimitives.ObjectFactory.CreateSolidCube(0.2f, Color4.HotPink)); render = new OpenTKPrimitives.RenderObject(water.GenWater(Color4.Red)); // GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); //GL.PatchParameter(PatchParameterInt.PatchVertices, 3); GL.PointSize(3); GL.Enable(EnableCap.DepthTest); Debug.WriteLine("OnLoad .. done"); }
private void SetupShaders() { //Lo hago con mis clases, que encapsulan el manejo de shaders. //1. Creamos los shaders, a partir de archivos. String vShaderFile = "files/shaders/vshader1.glsl"; String fShaderFile = "files/shaders/fshader1.glsl"; Shader vShader = new Shader(ShaderType.VertexShader, vShaderFile); Shader fShader = new Shader(ShaderType.FragmentShader, fShaderFile); //2. Los compilamos vShader.Compile(); fShader.Compile(); //3. Creamos el Programa de shader con ambos. sProgram = new ShaderProgram(); sProgram.AddShader(vShader); sProgram.AddShader(fShader); //4. Construimos (linkeamos) el programa. sProgram.Build(); //5. Ya podemos eliminar los shaders compilados. (Si no los vamos a usar en otro programa) vShader.Delete(); fShader.Delete(); }
public void Load() { _bitmap = new Bitmap(_voxelRTSWindow.Width, _voxelRTSWindow.Height); _voxelRTSWindow.Resize += (sender, e) => _isDirty = true; GL.GenTextures(1, out _texture); GL.BindTexture(TextureTarget.Texture2D, _texture); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); UpdateTexture(); _shader = new ShaderProgram(); _shader.OnMessage += _shader_OnMessage; using (var sr = new StreamReader("Shaders/TopMenu.Vert")) { _shader.AddShader(ShaderType.VertexShader, sr.ReadToEnd()); } using (var sr = new StreamReader("Shaders/TopMenu.Frag")) { _shader.AddShader(ShaderType.FragmentShader, sr.ReadToEnd()); } _shader.Link(); Loaded = true; }
public CubeModel() { vao = new VertexArray(); shaderProgram = new ShaderProgram(); shaderProgram.AddShader(ShaderType.VertexShader, VERT_SHADER); shaderProgram.AddShader(ShaderType.FragmentShader, FRAG_SHADER); shaderProgram.Link(); tex = new Texture("fanera.jpg"); Vertex[] data; UInt32[] indexes; var of = new ObjFile("cube.3dobj"); of.GetGeometry(out data, out indexes); elementCount = indexes.Length; ibo = new IndexBuffer(indexes); using (var vbo = new VertexBuffer(data)) { vao.AddBuffer(vbo, shaderProgram, Vertex.Attributes); } }
/// <summary> /// Called when the form is loaded. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private unsafe void OnFormLoad(object sender, EventArgs e) { #region Process List _wowComboBox.BeginUpdate(); _wowComboBox.Items.Clear(); var processList = System.Diagnostics.Process.GetProcessesByName("Wow").Select(p => new ProcessIdentifier { Name = p.ProcessName, ID = p.Id }).ToArray(); _wowComboBox.Items.AddRange(processList); _wowComboBox.EndUpdate(); #endregion #region Object viewers _gameObjectExplorer.SetRenderer <ObjectListRenderer <CGGameObject_C>, CGGameObject_C>(new GameobjectListRenderer()); _gameObjectExplorer.SetFilterSource <GameObjectType>(); _gameObjectExplorer.SetFilter <CGGameObject_C>((gameobject) => { if (string.IsNullOrEmpty(_gameObjectExplorer.FilterValue)) { return(true); } return(gameobject.ObjectType.ToString() == _gameObjectExplorer.FilterValue); }); _unitExplorer.SetRenderer <ObjectListRenderer <CGUnit_C>, CGUnit_C>(new EntityListRenderer()); _playerExplorer.SetRenderer <ObjectListRenderer <CGUnit_C>, CGUnit_C>(new EntityListRenderer()); _playerExplorer.SetFilterSource <Class>(); _playerExplorer.SetFilter <CGUnit_C>((player) => { if (string.IsNullOrEmpty(_playerExplorer.FilterValue)) { return(true); } return(player.Class.ToString() == _playerExplorer.FilterValue); }); #endregion #region Tab images tabControl1.ImageList = new ImageList() { ImageSize = new Size(20, 20) }; tabControl1.ImageList.Images.AddRange(new[] { Resources.Map, Resources.Person, Resources.Monster }); #endregion #region Rendering #if DEBUG glControl1.Context.ErrorChecking = true; GL.Enable(EnableCap.DebugOutput); GL.Enable(EnableCap.DebugOutputSynchronous); GL.DebugMessageCallback((DebugSource source, DebugType type, int id, DebugSeverity severity, int length, IntPtr messagePtr, IntPtr errorParam) => { if (id == 131169 || id == 131185 || id == 131218 || id == 131204) { return; } var oldForegroundColor = Console.ForegroundColor; var message = new string((sbyte *)messagePtr, 0, length, Encoding.ASCII); switch (severity) { case DebugSeverity.DebugSeverityNotification: Console.ForegroundColor = ConsoleColor.DarkYellow; break; case DebugSeverity.DebugSeverityHigh: Console.ForegroundColor = ConsoleColor.Red; break; case DebugSeverity.DebugSeverityMedium: Console.ForegroundColor = ConsoleColor.Blue; break; case DebugSeverity.DebugSeverityLow: Console.ForegroundColor = ConsoleColor.Green; break; } Console.WriteLine(message); Console.ForegroundColor = oldForegroundColor; }, IntPtr.Zero); #endif glControl1.Resize += (_, __) => { GL.Viewport(0, 0, glControl1.Width, glControl1.Height); if (Game.Camera != null) { Game.Camera.AspectRatio = glControl1.Width / (float)glControl1.Height; } }; GL.ClearColor(Color.Black); GL.Clear(ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit); GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Less); GL.Enable(EnableCap.Multisample); GL.Enable(EnableCap.CullFace); GL.CullFace(CullFaceMode.Back); var terrainProgram = new ShaderProgram(); terrainProgram.AddShader(ShaderType.VertexShader, "./shaders/terrain.vert"); terrainProgram.AddShader(ShaderType.FragmentShader, "./shaders/mixed.frag"); terrainProgram.AddShader(ShaderType.GeometryShader, "./shaders/mixed.geom"); terrainProgram.Link(); ShaderProgramCache.Instance.Add("terrain", terrainProgram); var wmoProgram = new ShaderProgram(); wmoProgram.AddShader(ShaderType.VertexShader, "./shaders/wmo.vert"); wmoProgram.AddShader(ShaderType.FragmentShader, "./shaders/mixed.frag"); wmoProgram.AddShader(ShaderType.GeometryShader, "./shaders/mixed.geom"); wmoProgram.Link(); ShaderProgramCache.Instance.Add("wmo", wmoProgram); #endregion }
public VoxelView() { square_vertices = new float[] { //Front Face -size, -size, size, size, -size, size, size, size, size, -size, size, size, //Back Face -size, -size, -size, -size, size, -size, size, size, -size, size, -size, -size, //Top Face -size, size, -size, -size, size, size, size, size, size, size, size, -size, //Bottom Face -size, -size, -size, size, -size, -size, size, -size, size, -size, -size, size, //Right Face size, -size, -size, size, size, -size, size, size, size, size, -size, size, //Left Face -size, -size, -size, -size, -size, size, -size, size, size, -size, size, -size }; Random rnd = new Random(); for (int i = 0; i < number; i++) { instance_positions[(i * 3)] = (float)(rnd.Next(-10, 10)); instance_positions[(i * 3) + 1] = (float)(rnd.Next(-10, 10)); instance_positions[(i * 3) + 2] = (float)(rnd.Next(-10, 10)); instance_colours[(i * 4)] = (float)rnd.NextDouble(); instance_colours[(i * 4) + 1] = (float)rnd.NextDouble(); instance_colours[(i * 4) + 2] = (float)rnd.NextDouble(); instance_colours[(i * 4) + 3] = 0.4f; instance_rotations[(i * 4)] = (float)rnd.NextDouble(); instance_rotations[(i * 4) + 1] = (float)rnd.NextDouble(); instance_rotations[(i * 4) + 2] = (float)rnd.NextDouble(); instance_rotations[(i * 4) + 3] = (float)rnd.NextDouble(); } shader = new ShaderProgram(); shader.OnMessage += new ShaderMessageEventHandler(shader_OnMessage); using (StreamReader sr = new StreamReader("Shaders/instancing.vertexshader")) { shader.AddShader(ShaderType.VertexShader, sr.ReadToEnd()); } using (StreamReader sr = new StreamReader("Shaders/instancing.fragmentshader")) { shader.AddShader(ShaderType.FragmentShader, sr.ReadToEnd()); } GL.BindAttribLocation(shader.Program, 0, "position"); GL.BindAttribLocation(shader.Program, 1, "instance_color"); GL.BindAttribLocation(shader.Program, 2, "instance_position"); GL.BindAttribLocation(shader.Program, 3, "instance_rotation"); shader.Link(); int square_vertices_size = square_vertices.Length * 4; int instance_colours_size = instance_colours.Length * 4; int instance_positions_size = instance_positions.Length * 4; int instance_rotations_size = instance_rotations.Length * 4; int offset = 0; GL.GenVertexArrays(1, out square_vao); GL.GenBuffers(1, out square_vbo); GL.BindVertexArray(square_vao); GL.BindBuffer(BufferTarget.ArrayBuffer, square_vbo); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(square_vertices_size + instance_colours_size + instance_positions_size + instance_rotations_size), IntPtr.Zero, BufferUsageHint.DynamicDraw); GL.BufferSubData <float>(BufferTarget.ArrayBuffer, (IntPtr)offset, (IntPtr)square_vertices_size, square_vertices); offset += square_vertices_size; GL.BufferSubData <float>(BufferTarget.ArrayBuffer, (IntPtr)offset, (IntPtr)instance_colours_size, instance_colours); offset += instance_colours_size; GL.BufferSubData <float>(BufferTarget.ArrayBuffer, (IntPtr)offset, (IntPtr)instance_positions_size, instance_positions); GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 0, 0); GL.VertexAttribPointer(1, 4, VertexAttribPointerType.Float, false, 0, square_vertices_size); GL.VertexAttribPointer(2, 3, VertexAttribPointerType.Float, false, 0, square_vertices_size + instance_colours_size); GL.VertexAttribPointer(3, 4, VertexAttribPointerType.Float, false, 0, square_vertices_size + instance_colours_size + instance_rotations_size); GL.EnableVertexAttribArray(0); GL.EnableVertexAttribArray(1); GL.EnableVertexAttribArray(2); GL.EnableVertexAttribArray(3); GL.Arb.VertexAttribDivisor(1, 1); GL.Arb.VertexAttribDivisor(2, 1); GL.Arb.VertexAttribDivisor(3, 1); }
public void Load() { GL.Enable(EnableCap.VertexProgramPointSize); _shader = new ShaderProgram(); //_shader.OnMessage += _shader_OnMessage; using (var sr = new StreamReader("Shaders/SkyBox.Vert")) { _shader.AddShader(ShaderType.VertexShader, sr.ReadToEnd()); } using (var sr = new StreamReader("Shaders/SkyBox.Frag")) { _shader.AddShader(ShaderType.FragmentShader, sr.ReadToEnd()); } _shader.Link(); _attribPosition = GL.GetAttribLocation(_shader.Program, "in_position"); _attribSize = GL.GetAttribLocation(_shader.Program, "in_size"); GL.BindAttribLocation(_shader.Program, _attribPosition, "in_position"); GL.BindAttribLocation(_shader.Program, _attribSize, "in_size"); _shader.Enable(); _uniformCamera = GL.GetUniformLocation(_shader.Program, "in_camera"); GL.Uniform3(_uniformCamera, new Vector3(0, 0, -30)); _shader.Disable(); //Console.WriteLine("pos:" + _attribPosition); //Console.WriteLine("size:" + _attribSize); //Console.WriteLine("uni:"+ _uniformCamera); var dataList = new List <float>(); var rnd = new Random(); double x1; double x2; const float radius = 30f; for (int i = 0; i < StarCount; i++) { x1 = rnd.Next(-1, 2) * rnd.NextDouble(); x2 = rnd.Next(-1, 2) * rnd.NextDouble(); var temp = PointLoc(x1, x2); dataList.Add(temp.Item1 * radius); dataList.Add(temp.Item2 * radius); dataList.Add(temp.Item3 * radius); dataList.Add((float)rnd.NextDouble() * 10f); } var data = dataList.ToArray(); GL.GenVertexArrays(1, out _vao); GL.GenBuffers(1, out _vbo); GL.BindVertexArray(_vao); GL.BindBuffer(BufferTarget.ArrayBuffer, _vbo); GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(data.Length * sizeof(float)), data, BufferUsageHint.StaticDraw); GL.VertexAttribPointer(_attribPosition, 3, VertexAttribPointerType.Float, false, 4 * sizeof(float), 0); GL.VertexAttribPointer(_attribSize, 1, VertexAttribPointerType.Float, false, 4 * sizeof(float), 3 * sizeof(float)); GL.EnableVertexAttribArray(_attribPosition); GL.EnableVertexAttribArray(_attribSize); GL.Arb.VertexAttribDivisor(_attribPosition, 1); GL.Arb.VertexAttribDivisor(_attribSize, 1); Loaded = true; }
/// <summary> /// Called when the form is loaded. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private unsafe void OnFormLoad(object sender, EventArgs e) { RefreshClientList(sender, e); #region Object viewers _gameObjectExplorer.SetRenderer <ObjectListRenderer <CGGameObject_C>, CGGameObject_C>(new GameobjectListRenderer()); _gameObjectExplorer.SetFilterSource <GameObjectType>(); _gameObjectExplorer.SetFilter <CGGameObject_C>((gameobject) => { if (string.IsNullOrEmpty(_gameObjectExplorer.FilterValue)) { return(true); } return(gameobject.ObjectType.ToString() == _gameObjectExplorer.FilterValue); }); _unitExplorer.SetRenderer <ObjectListRenderer <CGUnit_C>, CGUnit_C>(new EntityListRenderer()); _playerExplorer.SetRenderer <ObjectListRenderer <CGUnit_C>, CGUnit_C>(new EntityListRenderer()); _playerExplorer.SetFilterSource <Class>(); _playerExplorer.SetFilter <CGUnit_C>((player) => { if (string.IsNullOrEmpty(_playerExplorer.FilterValue)) { return(true); } return(player.Class.ToString() == _playerExplorer.FilterValue); }); #endregion #region Tab images tabControl1.ImageList = new ImageList() { ImageSize = new Size(20, 20) }; tabControl1.ImageList.Images.AddRange(new[] { Resources.Map, Resources.Person, Resources.Monster }); #endregion #region Rendering _renderControl.Paint += (_, __) => RenderGeometry(); _renderControl.Resize += (_, __) => { GeometryLoader.Buffer.Width = _renderControl.Width; GeometryLoader.Buffer.Height = _renderControl.Height; GL.Viewport(0, 0, _renderControl.Width, _renderControl.Height); if (Game.Camera != null) { Game.Camera.AspectRatio = _renderControl.Width / (float)_renderControl.Height; } }; GL.ClearColor(Color.Black); GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Less); GL.Clear(ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit); GL.Enable(EnableCap.Multisample); // Disable backface culling. some faces have their vertices in the wrong order. // GL.Enable(EnableCap.CullFace); // GL.CullFace(CullFaceMode.Back); var terrainProgram = new ShaderProgram(); terrainProgram.AddShader(ShaderType.VertexShader, "./shaders/terrain.vert"); terrainProgram.AddShader(ShaderType.FragmentShader, "./shaders/mixed.frag"); terrainProgram.AddShader(ShaderType.GeometryShader, "./shaders/mixed.geom"); terrainProgram.Link(); ShaderProgramCache.Instance.Add("terrain", terrainProgram); var wmoProgram = new ShaderProgram(); wmoProgram.AddShader(ShaderType.VertexShader, "./shaders/wmo.vert"); wmoProgram.AddShader(ShaderType.FragmentShader, "./shaders/mixed.frag"); wmoProgram.AddShader(ShaderType.GeometryShader, "./shaders/mixed.geom"); wmoProgram.Link(); ShaderProgramCache.Instance.Add("wmo", wmoProgram); var gameobjectProgram = new ShaderProgram(); gameobjectProgram.AddShader(ShaderType.VertexShader, "./shaders/gameobject.vert"); gameobjectProgram.AddShader(ShaderType.FragmentShader, "./shaders/mixed.frag"); gameobjectProgram.AddShader(ShaderType.GeometryShader, "./shaders/mixed.geom"); gameobjectProgram.Link(); ShaderProgramCache.Instance.Add("gameobject", gameobjectProgram); var quadProgram = new ShaderProgram(); quadProgram.AddShader(ShaderType.VertexShader, "./shaders/quad.vert"); quadProgram.AddShader(ShaderType.FragmentShader, "./shaders/quad.frag"); quadProgram.Link(); ShaderProgramCache.Instance.Add("quad", quadProgram); #endregion }