public UIText( System.Windows.Forms.AnchorStyles anchor, System.Windows.Forms.Padding margin, System.Drawing.Size size, int zNear, int zFar, FontResource fontResource = null, int maxCharCount = 100) : base(anchor, margin, size, zNear, zFar) { if (fontResource == null) { this.fontResource = FontResource.Default; } else { this.fontResource = fontResource; } this.Name = this.GetType().Name; var shaderCodes = new ShaderCode[2]; shaderCodes[0] = new ShaderCode(ManifestResourceLoader.LoadTextFile( @"Resources.UIText.vert"), ShaderType.VertexShader); shaderCodes[1] = new ShaderCode(ManifestResourceLoader.LoadTextFile( @"Resources.UIText.frag"), ShaderType.FragmentShader); var map = new PropertyNameMap(); map.Add("position", "position"); map.Add("uv", "uv"); var model = new TextModel(maxCharCount); Renderer renderer = new Renderer(model, shaderCodes, map); this.model = model; this.Renderer = renderer; }
private void Form_Load(object sender, EventArgs e) { { var camera = new Camera( new vec3(0, 0, 5), new vec3(0, 0, 0), new vec3(0, 1, 0), CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height); var rotator = new SatelliteManipulater(); rotator.Bind(camera, this.glCanvas1); this.camera = camera; this.rotator = rotator; } { IBufferable bufferable = new Teapot(); var shaderCodes = new ShaderCode[2]; shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\Transparent.vert"), ShaderType.VertexShader); shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\Transparent.frag"), ShaderType.FragmentShader); var map = new PropertyNameMap(); map.Add("in_Position", "position"); map.Add("in_Color", "color"); var renderer = new PickableRenderer(bufferable, shaderCodes, map, "position"); renderer.Name = "Order-Dependent Transparent Renderer"; renderer.Initialize(); { GLSwitch blendSwitch = new BlendSwitch(BlendingSourceFactor.SourceAlpha, BlendingDestinationFactor.OneMinusSourceAlpha); renderer.SwitchList.Add(blendSwitch); } this.renderer = renderer; } { var frmPropertyGrid = new FormProperyGrid(); frmPropertyGrid.DisplayObject(this.renderer); frmPropertyGrid.Show(); this.formPropertyGrid = frmPropertyGrid; } }
public OrderIndependentTransparencyRenderer(IBufferable model, string positionName, string normalName) { { var map = new PropertyNameMap(); map.Add("position", positionName); map.Add("normal", normalName); var build_lists = new ShaderCode[2]; build_lists[0] = new ShaderCode(File.ReadAllText(@"shaders\build_lists.vert"), ShaderType.VertexShader); build_lists[1] = new ShaderCode(File.ReadAllText(@"shaders\build_lists.frag"), ShaderType.FragmentShader); this.buildListsRenderer =new PickableRenderer(model, build_lists, map, positionName); } { var map = new PropertyNameMap(); map.Add("position", positionName); var resolve_lists = new ShaderCode[2]; resolve_lists[0] = new ShaderCode(File.ReadAllText(@"shaders\resolve_lists.vert"), ShaderType.VertexShader); resolve_lists[1] = new ShaderCode(File.ReadAllText(@"shaders\resolve_lists.frag"), ShaderType.FragmentShader); this.resolve_lists = new PickableRenderer(model, resolve_lists, map, positionName); } { this.depthTestSwitch = new DepthTestSwitch(false); this.cullFaceSwitch = new CullFaceSwitch(false); } }
private void InitBackfaceRenderer() { var shaderCodes = new ShaderCode[2]; shaderCodes[0] = new ShaderCode(File.ReadAllText(@"10RaycastVolumeRender\backface.vert"), ShaderType.VertexShader); shaderCodes[1] = new ShaderCode(File.ReadAllText(@"10RaycastVolumeRender\backface.frag"), ShaderType.FragmentShader); var map = new PropertyNameMap(); map.Add(RaycastModel.strPosition, RaycastModel.strPosition); map.Add(RaycastModel.strBoundingBox, RaycastModel.strBoundingBox); this.backfaceRenderer = new Renderer(model, shaderCodes, map); this.backfaceRenderer.Initialize(); this.backfaceRenderer.SwitchList.Add(new CullFaceSwitch(CullFaceMode.Front, true)); }
public static QuadStripRenderer Create(QuadStripModel model) { var shaderCodes = new ShaderCode[2]; shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\QuadStripTexture.vert"), ShaderType.VertexShader); shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\QuadStripTexture.frag"), ShaderType.FragmentShader); var map = new PropertyNameMap(); map.Add("in_Position", QuadStripModel.position); map.Add("in_TexCoord", QuadStripModel.texCoord); var renderer = new QuadStripRenderer(model, shaderCodes, map); return(renderer); }
public static QuadStripColoredRenderer Create(QuadStripColoredModel model) { var shaderCodes = new ShaderCode[2]; shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\QuadStripColor.vert"), ShaderType.VertexShader); shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\QuadStripColor.frag"), ShaderType.FragmentShader); var map = new PropertyNameMap(); map.Add("in_Position", QuadStripColoredModel.position); map.Add("in_Color", QuadStripColoredModel.color); var renderer = new QuadStripColoredRenderer(model, shaderCodes, map); renderer.quadCount = model.quadCount; return(renderer); }
public static OrderDependentTransparencyRenderer Create(IBufferable model, string position, string color) { var shaderCodes = new ShaderCode[2]; shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\Transparent.vert"), ShaderType.VertexShader); shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\Transparent.frag"), ShaderType.FragmentShader); var map = new PropertyNameMap(); map.Add("in_Position", position); map.Add("in_Color", color); var renderer = new OrderDependentTransparencyRenderer(model, shaderCodes, map, position, new BlendSwitch(BlendingSourceFactor.SourceAlpha, BlendingDestinationFactor.OneMinusSourceAlpha)); renderer.Name = "Order-Dependent Transparent Renderer"; return(renderer); }
public OrderIndependentTransparencyRenderer(IBufferable model, string positionName, string normalName) { { var map = new PropertyNameMap(); map.Add("position", positionName); map.Add("normal", normalName); var build_lists = new ShaderCode[2]; build_lists[0] = new ShaderCode(File.ReadAllText(@"02OrderIndependentTransparency\build_lists.vert"), ShaderType.VertexShader); build_lists[1] = new ShaderCode(File.ReadAllText(@"02OrderIndependentTransparency\build_lists.frag"), ShaderType.FragmentShader); this.buildListsRenderer = new PickableRenderer(model, build_lists, map, positionName); } { var map = new PropertyNameMap(); map.Add("position", positionName); var resolve_lists = new ShaderCode[2]; resolve_lists[0] = new ShaderCode(File.ReadAllText(@"02OrderIndependentTransparency\resolve_lists.vert"), ShaderType.VertexShader); resolve_lists[1] = new ShaderCode(File.ReadAllText(@"02OrderIndependentTransparency\resolve_lists.frag"), ShaderType.FragmentShader); this.resolve_lists = new PickableRenderer(model, resolve_lists, map, positionName); } { this.depthTestSwitch = new DepthTestSwitch(false); this.cullFaceSwitch = new CullFaceSwitch(false); } }
public static CatesianGridRenderer Create(vec3 originalWorldPosition, CatesianGrid grid, Texture codedColorSampler) { var shaderCodes = new ShaderCode[2]; shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\HexahedronGrid.vert"), ShaderType.VertexShader); shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\HexahedronGrid.frag"), ShaderType.FragmentShader); var map = new PropertyNameMap(); map.Add("in_Position", CatesianGrid.strPosition); map.Add("in_uv", CatesianGrid.strColor); var renderer = new CatesianGridRenderer(originalWorldPosition, grid, shaderCodes, map, codedColorSampler); renderer.lengths = grid.DataSource.SourceActiveBounds.Max - grid.DataSource.SourceActiveBounds.Min; renderer.ModelMatrix = glm.translate(mat4.identity(), -grid.DataSource.Position); return(renderer); }
static BackgroundStarsRenderer() { staticShaderCodes = new ShaderCode[2]; staticShaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\PointSprite.vert"), ShaderType.VertexShader); staticShaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\PointSprite.frag"), ShaderType.FragmentShader); map = new PropertyNameMap(); map.Add("position", "position"); }
static AnalyzedPointSpriteRenderer() { staticShaderCodes = new ShaderCode[2]; staticShaderCodes[0] = new ShaderCode(File.ReadAllText(@"08AnalyzedPointSprite\AnalyzedPointSprite.vert"), ShaderType.VertexShader); staticShaderCodes[1] = new ShaderCode(File.ReadAllText(@"08AnalyzedPointSprite\AnalyzedPointSprite.frag"), ShaderType.FragmentShader); map = new PropertyNameMap(); map.Add("position", "position"); }
static SimpleComputeRenderer() { staticShaderCodes = new ShaderCode[2]; staticShaderCodes[0] = new ShaderCode(File.ReadAllText(@"04SimpleCompute\compute.vert"), ShaderType.VertexShader); staticShaderCodes[1] = new ShaderCode(File.ReadAllText(@"04SimpleCompute\compute.frag"), ShaderType.FragmentShader); map = new PropertyNameMap(); map.Add(SimpleCompute.strPosition, "position"); }
static AnalyzedBillboardRenderer() { staticShaderCodes = new ShaderCode[2]; staticShaderCodes[0] = new ShaderCode(File.ReadAllText(@"08AnalyzedBillboard\AnalyzedBillboard.vert"), ShaderType.VertexShader); staticShaderCodes[1] = new ShaderCode(File.ReadAllText(@"08AnalyzedBillboard\AnalyzedBillboard.frag"), ShaderType.FragmentShader); map = new PropertyNameMap(); map.Add("position", "position"); }
private static PropertyNameMap GetMap(BuildInSceneObject buildIn) { var map = new PropertyNameMap(); switch (buildIn) { case BuildInSceneObject.Cube: map.Add("in_Position", Cube.strPosition); map.Add("in_Color", Cube.strColor); break; case BuildInSceneObject.Sphere: map.Add("in_Position", Sphere.strPosition); map.Add("in_Color", Sphere.strColor); break; case BuildInSceneObject.Ground: map.Add("in_Position", Ground.strPosition); map.Add("in_Color", Ground.strColor); break; case BuildInSceneObject.Axis: map.Add("in_Position", Axis.strPosition); map.Add("in_Color", Axis.strColor); break; default: throw new NotImplementedException(); } return map; }
private void Form02OrderIndependentTransparency_Load(object sender, EventArgs e) { { var camera = new Camera(CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height); camera.Position = new vec3(0, 0, 5); camera.Target = new vec3(0, 0, 0); camera.UpVector = new vec3(0, 1, 0); var rotator = new SatelliteRotator(camera); this.camera = camera; this.rotator = rotator; } { var shaderCodes = new ShaderCode[2]; shaderCodes[0] = new ShaderCode(File.ReadAllText(@"12Billboard\Cube.vert"), ShaderType.VertexShader); shaderCodes[1] = new ShaderCode(File.ReadAllText(@"12Billboard\Cube.frag"), ShaderType.FragmentShader); var map = new PropertyNameMap(); map.Add("in_Position", "position"); map.Add("in_Color", "color"); var cubeRenderer = new PickableRenderer(new Cube(), shaderCodes, map, "position"); cubeRenderer.Initialize(); this.cubeRenderer = cubeRenderer; } { var shaderCodes = new ShaderCode[2]; shaderCodes[0] = new ShaderCode(File.ReadAllText(@"12Billboard\billboard.vert"), ShaderType.VertexShader); shaderCodes[1] = new ShaderCode(File.ReadAllText(@"12Billboard\billboard.frag"), ShaderType.FragmentShader); var map = new PropertyNameMap(); map.Add("squareVertices", "position"); var billboardRenderer = new Renderer(new BillboardModel(), shaderCodes, map); billboardRenderer.Initialize(); var texture = new sampler2D(); var bitmap = new Bitmap(@"12Billboard\ExampleBillboard.png"); texture.Initialize(bitmap); bitmap.Dispose(); billboardRenderer.SetUniform("myTextureSampler", new samplerValue(BindTextureTarget.Texture2D, texture.Id, OpenGL.GL_TEXTURE0)); this.billboardRenderer = billboardRenderer; } { var UIRoot = new GLControl(this.glCanvas1.Size, -100, 100); UIRoot.Initialize(); this.uiRoot = UIRoot; var glAxis = new GLAxis(AnchorStyles.Right | AnchorStyles.Bottom, new Padding(3, 3, 3, 3), new Size(70, 70), -100, 100); glAxis.Initialize(); this.glAxis = glAxis; UIRoot.Controls.Add(glAxis); } { var frmPropertyGrid = new FormProperyGrid(); frmPropertyGrid.DisplayObject(this.glAxis); frmPropertyGrid.Show(); this.formPropertyGrid = frmPropertyGrid; } }
private void Form01ModernRenderer_Load(object sender, EventArgs e) { { var camera = new Camera(CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height); camera.Position = new vec3(0, 0, 5); var rotator = new SatelliteRotator(camera); this.camera = camera; this.rotator = rotator; } { IBufferable bufferable = new BigDipperAdapter(new BigDipper()); ShaderCode[] shaders = new ShaderCode[2]; shaders[0] = new ShaderCode(File.ReadAllText(@"Shaders\BigDipper.vert"), ShaderType.VertexShader); shaders[1] = new ShaderCode(File.ReadAllText(@"Shaders\BigDipper.frag"), ShaderType.FragmentShader); var propertyNameMap = new PropertyNameMap(); propertyNameMap.Add("in_Position", "position"); propertyNameMap.Add("in_Color", "color"); var renderer = new ModernRenderer(bufferable, shaders, propertyNameMap, "position"); renderer.Initialize(); GLSwitch lineWidthSwitch = new LineWidthSwitch(10.0f); renderer.SwitchList.Add(lineWidthSwitch); GLSwitch pointSizeSwitch = new PointSizeSwitch(10.0f); renderer.SwitchList.Add(pointSizeSwitch); this.renderer = renderer; } { var frmBulletinBoard = new FormBulletinBoard(); frmBulletinBoard.Dump = true; frmBulletinBoard.Show(); this.bulletinBoard = frmBulletinBoard; } { var frmPropertyGrid = new FormProperyGrid(); frmPropertyGrid.DisplayObject(this.renderer); frmPropertyGrid.Show(); this.rendererPropertyGrid = frmPropertyGrid; } { var frmPropertyGrid = new FormProperyGrid(); frmPropertyGrid.DisplayObject(this.camera); frmPropertyGrid.Show(); this.cameraPropertyGrid = frmPropertyGrid; } }
/// <summary> /// opengl UI for Axis /// </summary> /// <param name="anchor"></param> /// <param name="margin"></param> /// <param name="size"></param> /// <param name="zNear"></param> /// <param name="zFar"></param> public UIAxis( System.Windows.Forms.AnchorStyles anchor, System.Windows.Forms.Padding margin, System.Drawing.Size size, int zNear, int zFar) : base(anchor, margin, size, zNear, zFar) { this.Name = typeof(UIAxis).Name; var shaderCodes = new ShaderCode[2]; shaderCodes[0] = new ShaderCode(ManifestResourceLoader.LoadTextFile( @"Resources.UIAxis.vert"), ShaderType.VertexShader); shaderCodes[1] = new ShaderCode(ManifestResourceLoader.LoadTextFile( @"Resources.UIAxis.frag"), ShaderType.FragmentShader); var map = new PropertyNameMap(); map.Add("in_Position", "position"); map.Add("in_Color", "color"); //PickableRenderer renderer = (new Axis()).GetRenderer(shaderCodes, map, "position"); PickableRenderer renderer = new PickableRenderer(new Axis(), shaderCodes, map, "position"); this.Renderer = renderer; }
/// <summary> /// 支持UI布局的渲染器 /// </summary> /// <param name="modernRenderer">要渲染的对象</param> /// <param name="Anchor">绑定到窗口的哪些边?</param> /// <param name="Margin">到绑定边的距离</param> /// <param name="Size">UI大小</param> /// <param name="zNear"></param> /// <param name="zFar"></param> public UIAxisRenderer( System.Windows.Forms.AnchorStyles Anchor, System.Windows.Forms.Padding Margin, System.Drawing.Size Size, int zNear = -1000, int zFar = 1000 ) : base(null, Anchor, Margin, Size, zNear, zFar) { ShaderCode[] shaderCodes = new ShaderCode[2]; shaderCodes[0] = new ShaderCode(File.ReadAllText(@"01Renderer\Simple.vert"), ShaderType.VertexShader); shaderCodes[1] = new ShaderCode(File.ReadAllText(@"01Renderer\Simple.frag"), ShaderType.FragmentShader); var propertyNameMap = new PropertyNameMap(); propertyNameMap.Add("in_Position", "position"); propertyNameMap.Add("in_Color", "color"); PickableRenderer pickableRenderer = PickableRendererFactory.GetRenderer( new Axis(), shaderCodes, propertyNameMap, "position"); pickableRenderer.Name = string.Format("Pickable: [{0}]", "Axis"); pickableRenderer.Initialize(); { GLSwitch lineWidthSwitch = new LineWidthSwitch(10); pickableRenderer.SwitchList.Add(lineWidthSwitch); GLSwitch pointSizeSwitch = new PointSizeSwitch(10); pickableRenderer.SwitchList.Add(pointSizeSwitch); GLSwitch polygonModeSwitch = new PolygonModeSwitch(PolygonModes.Filled); pickableRenderer.SwitchList.Add(polygonModeSwitch); if (pickableRenderer is OneIndexRenderer) { GLSwitch primitiveRestartSwitch = new PrimitiveRestartSwitch((pickableRenderer as OneIndexRenderer).IndexBufferPtr); pickableRenderer.SwitchList.Add(primitiveRestartSwitch); } } this.renderer = pickableRenderer; this.textList.Add(new Tuple <vec3, string, Font, Color>(new vec3(offset, 0, 0), "X", new Font("Courier New", fontSize), Color.Red)); this.textList.Add(new Tuple <vec3, string, Font, Color>(new vec3(0, offset, 0), "Y", new Font("Courier New", fontSize), Color.Green)); this.textList.Add(new Tuple <vec3, string, Font, Color>(new vec3(0, 0, offset), "Z", new Font("Courier New", fontSize), Color.Blue)); }
public static BillboardRenderer GetRenderer(IBufferable model) { var shaderCodes = new ShaderCode[2]; shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\billboard.vert"), ShaderType.VertexShader); shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\billboard.frag"), ShaderType.FragmentShader); var map = new PropertyNameMap(); map.Add("in_Positions", BillboardModel.strPosition); var billboardRenderer = new BillboardRenderer(model, shaderCodes, map); return(billboardRenderer); }
public static GroundRenderer Create(GroundModel model) { var shaderCodes = new ShaderCode[2]; shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\Ground.vert"), ShaderType.VertexShader); shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\Ground.frag"), ShaderType.FragmentShader); var map = new PropertyNameMap(); map.Add("in_Position", GroundModel.strPosition); var ground = new GroundRenderer(model, shaderCodes, map); return(ground); }
//private vec3 scale; //public vec3 Scale //{ // get { return scale; } // set // { // if (value != scale) // { // scale = value; // if (this.initialized) // { // this.SetUniform("modelMatrix", // glm.scale(glm.translate(mat4.identity(), this.translate), this.scale)); // } // } // } //} //private vec3 translate; //public vec3 Translate //{ // get { return translate; } // set // { // if (value != translate) // { // translate = value; // if (this.initialized) // { // this.SetUniform("modelMatrix", // glm.scale(glm.translate(mat4.identity(), this.translate), this.scale)); // } // } // } //} public BoudingBoxRenderer(vec3 lengths) : base(null, null, null) { this.bufferable = new BoundingBox(lengths); var shaderCodes = new ShaderCode[2]; shaderCodes[0] = new ShaderCode(File.ReadAllText( @"shaders\BoundingBox.vert"), ShaderType.VertexShader); shaderCodes[1] = new ShaderCode(File.ReadAllText( @"shaders\BoundingBox.frag"), ShaderType.FragmentShader); this.shaderCodes = shaderCodes; var map = new PropertyNameMap(); map.Add("in_Position", BoundingBox.strPosition); this.propertyNameMap = map; this.switchList.Add(new PolygonModeSwitch(PolygonModes.Lines)); }
public static LinesRenderer Create(LinesModel model) { var shaderCodes = new ShaderCode[2]; shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\Lines.vert"), ShaderType.VertexShader); shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\Lines.frag"), ShaderType.FragmentShader); var map = new PropertyNameMap(); map.Add("in_Position", LinesModel.position); var renderer = new LinesRenderer(model, shaderCodes, map); renderer.markerCount = model.markerCount; return(renderer); }
/// <summary> /// get a bounding box renderer. /// </summary> /// <param name="lengths">bounding box's length at x, y, z axis.</param> /// <returns></returns> public static Renderer GetBoundingBoxRenderer(vec3 lengths) { var bufferable = new BoundingBox(lengths); var shaderCodes = new ShaderCode[2]; shaderCodes[0] = new ShaderCode(File.ReadAllText( @"shaders\BoundingBox.vert"), ShaderType.VertexShader); shaderCodes[1] = new ShaderCode(File.ReadAllText( @"shaders\BoundingBox.frag"), ShaderType.FragmentShader); var map = new PropertyNameMap(); map.Add("in_Position", BoundingBox.strPosition); var result = new Renderer(bufferable, shaderCodes, map, new PolygonModeSwitch(PolygonModes.Lines), new PolygonOffsetFillSwitch()); return(result); }
public static TerrainRenderer GetRenderer(IList <vec3> positions) { BoundingBox boundingBox = positions.Move2Center(); IBufferable model = new TerrainModel(positions); var shaderCodes = new ShaderCode[2]; shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\Terrain.vert"), ShaderType.VertexShader); shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\Terrain.frag"), ShaderType.FragmentShader); var map = new PropertyNameMap(); map.Add("in_Position", TerrainModel.strPosition); var renderer = new TerrainRenderer(model, shaderCodes, map, boundingBox, new PointSizeSwitch(10)); return(renderer); }
protected override void DoInitialize() { { IBufferable bufferable = new ParticleModel(); var shaderCodes = new ShaderCode[2]; shaderCodes[0] = new ShaderCode(File.ReadAllText(@"05ParticleSimulator\particleSimulator.vert"), ShaderType.VertexShader); shaderCodes[1] = new ShaderCode(File.ReadAllText(@"05ParticleSimulator\particleSimulator.frag"), ShaderType.FragmentShader); var map = new PropertyNameMap(); map.Add("position", ParticleModel.strPosition); var particleRenderer = new ParticleRenderer(bufferable, shaderCodes, map, new DepthTestSwitch(false), new BlendSwitch(BlendingSourceFactor.One, BlendingDestinationFactor.One)); particleRenderer.Initialize(); this.particleRenderer = particleRenderer; } { var particleComputeRenderer = new ParticleComputeRenderer( this.particleRenderer.PositionBufferPtr.BufferId, this.particleRenderer.VelocityBufferPtrId); particleComputeRenderer.Initialize(); this.particleComputeRenderer = particleComputeRenderer; } }
protected override void DoInitialize() { { var computeProgram = new ShaderProgram(); var shaderCode = new ShaderCode(File.ReadAllText( @"06ImageProcessing\ImageProcessing.comp"), ShaderType.ComputeShader); var shader = shaderCode.CreateShader(); computeProgram.Create(shader); shader.Delete(); this.computeProgram = computeProgram; } { Bitmap bitmap = new System.Drawing.Bitmap(this.textureFilename); if (bitmap.Width != 512 || bitmap.Height != 512) { bitmap = (Bitmap)bitmap.GetThumbnailImage(512, 512, null, IntPtr.Zero); } OpenGL.GenTextures(1, this.input_image); OpenGL.BindTexture(OpenGL.GL_TEXTURE_2D, this.input_image[0]); // Lock the image bits (so that we can pass them to OGL). BitmapData bitmapData = bitmap.LockBits( new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); //GL.ActiveTexture(GL.GL_TEXTURE0); OpenGL.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, (int)OpenGL.GL_RGBA32F, bitmap.Width, bitmap.Height, 0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE, bitmapData.Scan0); // Unlock the image. bitmap.UnlockBits(bitmapData); /* We require 1 byte alignment when uploading texture data */ //GL.PixelStorei(GL.GL_UNPACK_ALIGNMENT, 1); /* Clamping to edges is important to prevent artifacts when scaling */ OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_S, (int)OpenGL.GL_CLAMP_TO_EDGE); OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_T, (int)OpenGL.GL_CLAMP_TO_EDGE); /* Linear filtering usually looks best for text */ OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, (int)OpenGL.GL_LINEAR); OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, (int)OpenGL.GL_LINEAR); bitmap.Dispose(); } { //GL.ActiveTexture(GL.GL_TEXTURE0); OpenGL.GenTextures(1, this.intermediate_image); OpenGL.BindTexture(OpenGL.GL_TEXTURE_2D, this.intermediate_image[0]); OpenGL.TexStorage2D(TexStorage2DTarget.Texture2D, 8, OpenGL.GL_RGBA32F, 512, 512); } { // This is the texture that the compute program will write into //GL.ActiveTexture(GL.GL_TEXTURE0); OpenGL.GenTextures(1, this.output_image); OpenGL.BindTexture(OpenGL.GL_TEXTURE_2D, this.output_image[0]); OpenGL.TexStorage2D(TexStorage2DTarget.Texture2D, 8, OpenGL.GL_RGBA32F, 512, 512); } { var bufferable = new ImageProcessingModel(); ShaderCode[] simpleShader = new ShaderCode[2]; simpleShader[0] = new ShaderCode(File.ReadAllText(@"06ImageProcessing\ImageProcessing.vert"), ShaderType.VertexShader); simpleShader[1] = new ShaderCode(File.ReadAllText(@"06ImageProcessing\ImageProcessing.frag"), ShaderType.FragmentShader); var propertyNameMap = new PropertyNameMap(); propertyNameMap.Add("vert", "position"); propertyNameMap.Add("uv", "uv"); var pickableRenderer = new PickableRenderer( bufferable, simpleShader, propertyNameMap, "position"); pickableRenderer.Name = string.Format("Pickable: [ImageProcessingRenderer]"); pickableRenderer.Initialize(); pickableRenderer.SetUniform("output_image", new samplerValue( BindTextureTarget.Texture2D, this.output_image[0], OpenGL.GL_TEXTURE0)); this.renderer = pickableRenderer; } }
private void Form01Renderer_Load(object sender, EventArgs e) { { var camera = new Camera(CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height); camera.Position = new vec3(0, 0, 5); var rotator = new SatelliteRotator(camera); this.camera = camera; this.rotator = rotator; } { // build several models Random random = new Random(); var bufferables = new IBufferable[] { new Axis(), new BigDipper(), new Chain(new ChainModel(random.Next(7, 100), 5, 5)), new Tetrahedron(), new Cube(), new Sphere(), new Teapot(), }; var keys = new GeometryModel[] { GeometryModel.Axis, GeometryModel.BigDipper, GeometryModel.Chain, GeometryModel.Tetrahedron, GeometryModel.Cube, GeometryModel.Sphere, GeometryModel.Teapot, }; ShaderCode[] simpleShader = new ShaderCode[2]; simpleShader[0] = new ShaderCode(File.ReadAllText(@"01Renderer\Simple.vert"), ShaderType.VertexShader); simpleShader[1] = new ShaderCode(File.ReadAllText(@"01Renderer\Simple.frag"), ShaderType.FragmentShader); ShaderCode[] emitNormalLineShader = new ShaderCode[3]; emitNormalLineShader[0] = new ShaderCode(File.ReadAllText(@"01Renderer\EmitNormalLine.vert"), ShaderType.VertexShader); emitNormalLineShader[1] = new ShaderCode(File.ReadAllText(@"01Renderer\EmitNormalLine.geom"), ShaderType.GeometryShader); emitNormalLineShader[2] = new ShaderCode(File.ReadAllText(@"01Renderer\EmitNormalLine.frag"), ShaderType.FragmentShader); var shaderCodesGroup = new ShaderCode[][] { simpleShader, simpleShader, simpleShader, emitNormalLineShader, emitNormalLineShader, emitNormalLineShader, emitNormalLineShader, }; var simpleShaderPropertyNameMap = new PropertyNameMap(); simpleShaderPropertyNameMap.Add("in_Position", "position"); simpleShaderPropertyNameMap.Add("in_Color", "color"); var emitNormalLineShaderPropertyNameMap = new PropertyNameMap(); emitNormalLineShaderPropertyNameMap.Add("in_Position", "position"); emitNormalLineShaderPropertyNameMap.Add("in_Normal", "normal"); var propertyNameMaps = new PropertyNameMap[] { simpleShaderPropertyNameMap, simpleShaderPropertyNameMap, simpleShaderPropertyNameMap, emitNormalLineShaderPropertyNameMap, emitNormalLineShaderPropertyNameMap, emitNormalLineShaderPropertyNameMap, emitNormalLineShaderPropertyNameMap, }; var positionNameInIBufferables = new string[] { "position", "position", "position", "position", "position", "position", "position", }; var uniformTupleList = new List <Tuple <string, ValueType> >() { new Tuple <string, ValueType>("normalLength", 0.5f), new Tuple <string, ValueType>("showModel", true), new Tuple <string, ValueType>("showNormal", false), }; var uniformVariablesList = new List <List <Tuple <string, ValueType> > >() { new List <Tuple <string, ValueType> >(), new List <Tuple <string, ValueType> >(), new List <Tuple <string, ValueType> >(), uniformTupleList, uniformTupleList, uniformTupleList, uniformTupleList, }; for (int i = 0; i < bufferables.Length; i++) { GeometryModel key = keys[i]; IBufferable bufferable = bufferables[i]; ShaderCode[] shaders = shaderCodesGroup[i]; var propertyNameMap = propertyNameMaps[i]; string positionNameInIBufferable = positionNameInIBufferables[i]; var highlightRenderer = new HighlightRenderer( bufferable, positionNameInIBufferable); highlightRenderer.Name = string.Format("Highlight: [{0}]", key); highlightRenderer.Initialize(); var pickableRenderer = new PickableRenderer( bufferable, shaders, propertyNameMap, positionNameInIBufferable); pickableRenderer.Name = string.Format("Pickable: [{0}]", key); pickableRenderer.Initialize(); var uniformVariables = uniformVariablesList[i]; foreach (var item in uniformVariables) { pickableRenderer.SetUniform(item.Item1, item.Item2); } HighlightedPickableRenderer renderer = new HighlightedPickableRenderer( highlightRenderer, pickableRenderer); renderer.Initialize(); { GLSwitch lineWidthSwitch = new LineWidthSwitch(5); pickableRenderer.SwitchList.Add(lineWidthSwitch); GLSwitch pointSizeSwitch = new PointSizeSwitch(10); pickableRenderer.SwitchList.Add(pointSizeSwitch); GLSwitch polygonModeSwitch = new PolygonModeSwitch(PolygonModes.Filled); pickableRenderer.SwitchList.Add(polygonModeSwitch); //GLSwitch blendSwitch = new BlendSwitch(); //pickableRenderer.SwitchList.Add(blendSwitch); } this.rendererDict.Add(key, renderer); } this.SelectedModel = GeometryModel.Tetrahedron; } { // build the axis var bufferables = new IBufferable[] { new Axis(), }; var keys = new GeometryModel[] { GeometryModel.Axis, }; ShaderCode[] simpleShader = new ShaderCode[2]; simpleShader[0] = new ShaderCode(File.ReadAllText(@"01Renderer\Simple.vert"), ShaderType.VertexShader); simpleShader[1] = new ShaderCode(File.ReadAllText(@"01Renderer\Simple.frag"), ShaderType.FragmentShader); var shaderCodesGroup = new ShaderCode[][] { simpleShader, }; var simpleShaderPropertyNameMap = new PropertyNameMap(); simpleShaderPropertyNameMap.Add("in_Position", "position"); simpleShaderPropertyNameMap.Add("in_Color", "color"); var propertyNameMaps = new PropertyNameMap[] { simpleShaderPropertyNameMap, }; var positionNameInIBufferables = new string[] { "position", }; var uniformVariablesList = new List <List <Tuple <string, ValueType> > >() { new List <Tuple <string, ValueType> >(), }; for (int i = 0; i < bufferables.Length; i++) { GeometryModel key = keys[i]; IBufferable bufferable = bufferables[i]; ShaderCode[] shaders = shaderCodesGroup[i]; var propertyNameMap = propertyNameMaps[i]; string positionNameInIBufferable = positionNameInIBufferables[i]; var pickableRenderer = new PickableRenderer( bufferable, shaders, propertyNameMap, positionNameInIBufferable); pickableRenderer.Name = string.Format("Pickable: [{0}]", key); pickableRenderer.Initialize(); var uniformVariables = uniformVariablesList[i]; foreach (var item in uniformVariables) { pickableRenderer.SetUniform(item.Item1, item.Item2); } } } { var frmBulletinBoard = new FormBulletinBoard(); //frmBulletinBoard.Dump = true; frmBulletinBoard.Show(); this.pickedGeometryBoard = frmBulletinBoard; } { var UIRoot = new GLControl(this.glCanvas1.Size, -100, 100); UIRoot.Initialize(); this.uiRoot = UIRoot; var glAxis = new GLAxis(AnchorStyles.Right | AnchorStyles.Bottom, new Padding(3, 3, 3, 3), new Size(70, 70), -100, 100); glAxis.Initialize(); this.glAxis = glAxis; UIRoot.Controls.Add(glAxis); } { var frmPropertyGrid = new FormProperyGrid(); frmPropertyGrid.DisplayObject(this.rendererDict[this.SelectedModel].PickableRenderer); frmPropertyGrid.Show(); this.pickableRendererPropertyGrid = frmPropertyGrid; } { var frmPropertyGrid = new FormProperyGrid(); frmPropertyGrid.DisplayObject(this.rendererDict[this.SelectedModel].Highlighter); frmPropertyGrid.Show(); this.highlightRendererPropertyGrid = frmPropertyGrid; } { var frmPropertyGrid = new FormProperyGrid(); frmPropertyGrid.DisplayObject(this); frmPropertyGrid.Show(); this.formPropertyGrid = frmPropertyGrid; } { var frmIndexBufferPtrBoard = new FormIndexBufferPtrBoard(); frmIndexBufferPtrBoard.SetTarget(this.rendererDict[this.SelectedModel].PickableRenderer.IndexBufferPtr); frmIndexBufferPtrBoard.Show(); this.frmIndexBufferPtrBoard = frmIndexBufferPtrBoard; } }
private void mniLoadECLGrid_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() != DialogResult.OK) { return; } //ModelContainer modelContainer = this.ModelContainer; string fileName = openFileDialog1.FileName; SimulationInputData inputData; try { inputData = this.LoadEclInputData(fileName); } catch (Exception err) { MessageBox.Show(String.Format("Load Error,{0}", err.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { List<GridBlockProperty> gridProps = inputData.RootDataFile.GetGridProperties(); GridBlockProperty gbp = gridProps[0]; double axisMin, axisMax, step; ColorIndicatorAxisAutomator.Automate(gbp.MinValue, gbp.MaxValue, out axisMin, out axisMax, out step); CatesianGrid grid = inputData.DumpCatesianGrid((float)axisMin, (float)axisMax); var shaderCodes = new ShaderCode[2]; shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\HexahedronGrid.vert"), ShaderType.VertexShader); shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\HexahedronGrid.frag"), ShaderType.FragmentShader); var map = new PropertyNameMap(); map.Add("in_Position", CatesianGrid.strPosition); map.Add("in_uv", CatesianGrid.strColor); var scientificRenderer = new Renderer(grid, shaderCodes, map); var boundedRenderer = new BoundedRenderer(scientificRenderer, grid.DataSource.SourceActiveBounds.Max - grid.DataSource.SourceActiveBounds.Min); boundedRenderer.Initialize(); SceneObject sceneObject = new SceneObject(); sceneObject.Name = typeof(CatesianGrid).Name; sceneObject.Renderer = new BoundedRendererComponent(boundedRenderer); //sceneObject.Transform.Position = grid.DataSource.TranslateMatrix; this.scientificCanvas.Scene.ObjectList.Add(sceneObject); //sceneObject.Renderer=ne //SimLabGrid gridder = null; //try //{ // gridderSource = CreateGridderSource(inputData); //} //catch (Exception err) //{ // MessageBox.Show(String.Format("Create Gridder Failed,{0}", err.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); // return; //} //if (gridderSource != null) //{ // string caseFileName = System.IO.Path.GetFileName(fileName); // TreeNode gridderNode = this.objectsTreeView.Nodes.Add(caseFileName); // gridderNode.ToolTipText = fileName; // List<GridBlockProperty> gridProps = inputData.RootDataFile.GetGridProperties(); // if (gridProps.Count <= 0) // { // GridBlockProperty gbp = this.CreateGridSequenceGridBlockProperty(gridderSource, "INDEX"); // gridProps.Add(gbp); // } // foreach (GridBlockProperty gbp in gridProps) // { // TreeNode propNode = gridderNode.Nodes.Add(gbp.Name); // propNode.Tag = gbp; // } // vec3 boundMin; // vec3 boundMax; // gridder = CreateGridder(gridderSource, gridProps[0], out boundMin, out boundMax); // if (gridder != null) // { // this.objectsTreeView.ExpandAll(); // //modelContainer.AddChild(gridder); // //modelContainer.BoundingBox.SetBounds(gridderSource.TransformedActiveBounds.Min, gridderSource.TransformedActiveBounds.Max); // //this.scene.ViewType = ViewTypes.UserView; // gridderNode.Tag = gridder; // gridder.Tag = gridderSource; // gridderSource.Tag = gridderNode.Nodes[0]; // gridderNode.Checked = gridder.IsEnabled; // gridderNode.Nodes[0].Checked = true; // } //List<Well> well3dList; //try //{ // well3dList = this.CreateWell3D(inputData, this.scene, gridderSource); //} //catch (Exception err) //{ // MessageBox.Show(String.Format("Create Well3d,{0}", err.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); // return; //} //if (well3dList != null && well3dList.Count > 0) // this.AddWellNodes(gridderNode, this.scene, well3dList); //} } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
//Camera modelRotationCamera; //SatelliteRotator modelRotator; //private float rotateAngle; public FormNewNormalLine() { InitializeComponent(); this.camera = new Camera(CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height); this.camera.Position = new GLM.vec3(50, 5, 5); this.cameraRotator = new SatelliteRotator(this.camera); //this.modelRotationCamera = new Camera(CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height); //this.modelRotator = new SatelliteRotator(this.modelRotationCamera); this.modelRotator = new ArcBallRotator(this.camera); { const string strGround = "Ground"; IConvert2BufferPointer model = new Ground(); CodeShader[] shaders = new CodeShader[2]; shaders[0] = CSharpGL.Objects.Common.ShaderLoadingHelper.LoadShaderSourceCode(strGround, CodeShader.GLSLShaderType.VertexShader); shaders[1] = CSharpGL.Objects.Common.ShaderLoadingHelper.LoadShaderSourceCode(strGround, CodeShader.GLSLShaderType.FragmentShader); PropertyNameMap propertyNameMap = CSharpGL.Objects.Common.ShaderLoadingHelper.LoadPropertyNameMap(strGround); UniformNameMap uniformNameMap = CSharpGL.Objects.Common.ShaderLoadingHelper.LoadUniformNameMap(strGround); this.groundRenderer = new ModernRenderer(model, shaders, propertyNameMap, uniformNameMap); this.groundRenderer.Initialize(); } Padding uiPadding = new System.Windows.Forms.Padding(10, 10, 10, 10); Size uiSize = new System.Drawing.Size(50, 50); IUILayoutParam uiParam = new IUILayoutParam(AnchorStyles.Left | AnchorStyles.Bottom, uiPadding, uiSize); uiAxis = new SimpleUIAxis(uiParam); uiAxis.Initialize(); //IModel model = (new TeapotFactory()).Create(1.0f); { IConvert2BufferPointer model = new NewNormalLineDemoModel(); CodeShader[] codeShaders = new CodeShader[3]; codeShaders[0] = new CodeShader(ShaderHelper.Load("NewNormalLine.vert"), CodeShader.GLSLShaderType.VertexShader); codeShaders[1] = new CodeShader(ShaderHelper.Load("NewNormalLine.geom"), CodeShader.GLSLShaderType.GeometryShader); codeShaders[2] = new CodeShader(ShaderHelper.Load("NewNormalLine.frag"), CodeShader.GLSLShaderType.FragmentShader); var propertyNameMap = new PropertyNameMap(); propertyNameMap.Add("in_Position", NewNormalLineDemoModel.strPosition); propertyNameMap.Add("in_Normal", NewNormalLineDemoModel.strNormal); var uniformNameMap = new UniformNameMap(); uniformNameMap.Add("model matrix", "modelMatrix"); uniformNameMap.Add("view matrix", "viewMatrix"); uniformNameMap.Add("projection matrix", "projectionMatrix"); uniformNameMap.Add("show model", "showModel"); uniformNameMap.Add("show normal", "showNormal"); uniformNameMap.Add("normal length", "normalLength"); this.renderer = new ModernRenderer(model, codeShaders, propertyNameMap, uniformNameMap); this.renderer.Initialize();//不在此显式初始化也可以。 this.renderer.SetUniformValue("show model", 1.0f); this.renderer.SetUniformValue("show normal", 1.0f); this.renderer.SetUniformValue("normal length", 1.0f); } //this.demoLifebar = new DemoLifeBar(0.2f, 0.02f, 4); //this.demolifebarRenderer = new NormalLineRenderer(this.demoLifebar); //this.demolifebarRenderer.Initialize(); this.lifebarRenderer = new LifeBarRenderer(new LifeBar(2f, 0.2f, 4f)); this.lifebarRenderer.Initialize(); //StringModel stringModel = DummyStringModelFactory.GetModel("teapot"); this.stringRenderer = new StringRenderer("teapot".GetDummyModel()); this.stringRenderer.Initialize(); uiParam = new IUILayoutParam(AnchorStyles.Right | AnchorStyles.Bottom, new Padding(10, 10, 120, 10), new Size(50, 50)); this.label = new DummyLabel(uiParam, "Hello Label!"); this.label.Initialize(); this.glCanvas1.MouseWheel += glCanvas1_MouseWheel; this.glCanvas1.KeyPress += glCanvas1_KeyPress; this.glCanvas1.MouseDown += glCanvas1_MouseDown; this.glCanvas1.MouseMove += glCanvas1_MouseMove; this.glCanvas1.MouseUp += glCanvas1_MouseUp; this.glCanvas1.OpenGLDraw += glCanvas1_OpenGLDraw; this.glCanvas1.Resize += glCanvas1_Resize; Application.Idle += Application_Idle; }
void FormMain_Load(object sender, EventArgs e) { { var camera = new Camera( new vec3(0, 0, (float)(Earth.revolutionRadius * 1.1)), new vec3(0, 0, 0), new vec3(0, 1, 0), CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height); IPerspectiveViewCamera perspecitve = camera; perspecitve.Near = 1; perspecitve.Far = Earth.revolutionRadius * 5; var rotator = new SatelliteRotator(camera); this.camera = camera; this.rotator = rotator; } { const int latitude = 180; //从南到北,纬度共有180° const int hour = 24; //24小时,24个时区 const int longitudePerHour = 15; // 每个时区占有的经度为15° const int longitude = hour * longitudePerHour; // 从东到西,经度共有360° IBufferable bufferable = new CelestialBody(1, latitude, longitude); var shaderCodes = new ShaderCode[2]; shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\CelestialBody.vert"), ShaderType.VertexShader); shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\CelestialBody.frag"), ShaderType.FragmentShader); var map = new PropertyNameMap(); map.Add("inPosition", CelestialBody.strPosition); map.Add("inUV", CelestialBody.strUV); var earthRenderer = new PickableRenderer(bufferable, shaderCodes, map, CelestialBody.strPosition); earthRenderer.Initialize(); earthRenderer.Name = "Earth 地球"; this.earthRenderer = earthRenderer; } { // Ecliptic: 黄道 IBufferable bufferable = new Circle((float)Earth.revolutionRadius); var shaderCodes = new ShaderCode[2]; shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\Circle.vert"), ShaderType.VertexShader); shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\Circle.frag"), ShaderType.FragmentShader); var map = new PropertyNameMap(); map.Add("inPosition", Circle.strPosition); var eclipticRenderer = new Renderer(bufferable, shaderCodes, map); eclipticRenderer.Initialize(); eclipticRenderer.Name = "Ecliptic 黄道"; this.eclipticRenderer = eclipticRenderer; } { const int latitude = 180; //从南到北,纬度共有180° const int hour = 24; //24小时,24个时区 const int longitudePerHour = 15; // 每个时区占有的经度为15° const int longitude = hour * longitudePerHour; // 从东到西,经度共有360° IBufferable bufferable = new CelestialBody((float)Sun.radius, latitude, longitude); var shaderCodes = new ShaderCode[2]; shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\Sun.vert"), ShaderType.VertexShader); shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\Sun.frag"), ShaderType.FragmentShader); var map = new PropertyNameMap(); map.Add("inPosition", CelestialBody.strPosition); var sunRenderer = new PickableRenderer(bufferable, shaderCodes, map, CelestialBody.strPosition); sunRenderer.Initialize(); sunRenderer.Name = "Sun 太阳"; this.sunRenderer = sunRenderer; } { var sunshineRenderer = new SunshineRenderer(); this.sunshineRenderer = sunshineRenderer; } { var backgroundStars = new BackgroundStarsRenderer(2000, Earth.revolutionRadius); backgroundStars.Initialize(); backgroundStars.Name = "stars 星星"; this.backgroundStars = backgroundStars; } { var glAxis = new GLAxis(AnchorStyles.Left | AnchorStyles.Bottom, new Padding(5, 5, 5, 5), new Size(100, 100), -100, 100); glAxis.Initialize(); this.glAxis = glAxis; } { var uiRoot = new GLControl(this.glCanvas1.Size, -100, 100); uiRoot.Initialize(); this.uiRoot = uiRoot; } { this.uiRoot.Controls.Add(this.glAxis); } { var earthColorTexture = new sampler2D(); var bitmap = new Bitmap(@"Images\earth-color-map-10800-5400.jpg"); earthColorTexture.Initialize(bitmap); bitmap.Dispose(); this.earthColorTexture = earthColorTexture; } { this.eclipticRenderer.SetUniform("color", new vec4(1.0f, 1.0f, 0.0f, 0.1f)); this.eclipticRenderer.SwitchList.Add(new PolygonModeSwitch(PolygonModes.Points)); } { this.earthRenderer.SetUniform("colorTexture", new samplerValue(BindTextureTarget.Texture2D, this.earthColorTexture.Id, OpenGL.GL_TEXTURE0)); //this.earthRenderer.SwitchList.Add(new CullFaceSwitch()); //this.sunRenderer.SwitchList.Add(new CullFaceSwitch()); } { var earth = new Earth(); this.earth = earth; this.thingList.Add(earth); } { var sun = new Sun(); this.sun = sun; this.thingList.Add(sun); } { var tracer = new CameraTracer(this.camera, this.earth, this.sun); this.tracer = tracer; this.thingList.Add(tracer); } { var frmPropertyGrid = new FormProperyGrid(); frmPropertyGrid.DisplayObject(this); frmPropertyGrid.Show(); } { var frmPropertyGrid = new FormProperyGrid(); frmPropertyGrid.DisplayObject(this.earthRenderer); frmPropertyGrid.Show(); } { var frmPropertyGrid = new FormProperyGrid(); frmPropertyGrid.DisplayObject(this.sunRenderer); frmPropertyGrid.Show(); } { var frmPropertyGrid = new FormProperyGrid(); frmPropertyGrid.DisplayObject(this.eclipticRenderer); frmPropertyGrid.Show(); } { var frmPropertyGrid = new FormProperyGrid(); frmPropertyGrid.DisplayObject(this.tracer); frmPropertyGrid.Show(); } { this.TimeSpeed = 14400; } }
private void Form_Load(object sender, EventArgs e) { { var camera = new Camera( new vec3(0, 0, 5), new vec3(), new vec3(0, 1, 0), CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height); var rotator = new SatelliteManipulater(); rotator.Bind(camera, this.glCanvas1); this.camera = camera; } { // build several models Random random = new Random(); var bufferables = new IBufferable[] { new Axis(), new BigDipper(), new Chain(new ChainModel(random.Next(7, 100), 5, 5)), new Tetrahedron(), new Cube(), new Sphere(), new Teapot(), }; var keys = new GeometryModel[] { GeometryModel.Axis, GeometryModel.BigDipper, GeometryModel.Chain, GeometryModel.Tetrahedron, GeometryModel.Cube, GeometryModel.Sphere, GeometryModel.Teapot, }; ShaderCode[] simpleShader = new ShaderCode[2]; simpleShader[0] = new ShaderCode(File.ReadAllText(@"shaders\Simple.vert"), ShaderType.VertexShader); simpleShader[1] = new ShaderCode(File.ReadAllText(@"shaders\Simple.frag"), ShaderType.FragmentShader); ShaderCode[] emitNormalLineShader = new ShaderCode[3]; emitNormalLineShader[0] = new ShaderCode(File.ReadAllText(@"shaders\EmitNormalLine.vert"), ShaderType.VertexShader); emitNormalLineShader[1] = new ShaderCode(File.ReadAllText(@"shaders\EmitNormalLine.geom"), ShaderType.GeometryShader); emitNormalLineShader[2] = new ShaderCode(File.ReadAllText(@"shaders\EmitNormalLine.frag"), ShaderType.FragmentShader); var shaderCodesGroup = new ShaderCode[][] { simpleShader, simpleShader, simpleShader, emitNormalLineShader, emitNormalLineShader, emitNormalLineShader, emitNormalLineShader, }; var simpleShaderPropertyNameMap = new PropertyNameMap(); simpleShaderPropertyNameMap.Add("in_Position", "position"); simpleShaderPropertyNameMap.Add("in_Color", "color"); var emitNormalLineShaderPropertyNameMap = new PropertyNameMap(); emitNormalLineShaderPropertyNameMap.Add("in_Position", "position"); emitNormalLineShaderPropertyNameMap.Add("in_Normal", "normal"); var propertyNameMaps = new PropertyNameMap[] { simpleShaderPropertyNameMap, simpleShaderPropertyNameMap, simpleShaderPropertyNameMap, emitNormalLineShaderPropertyNameMap, emitNormalLineShaderPropertyNameMap, emitNormalLineShaderPropertyNameMap, emitNormalLineShaderPropertyNameMap, }; var positionNameInIBufferables = new string[] { "position", "position", "position", "position", "position", "position", "position", }; for (int i = 0; i < bufferables.Length; i++) { GeometryModel key = keys[i]; IBufferable bufferable = bufferables[i]; ShaderCode[] shaders = shaderCodesGroup[i]; var propertyNameMap = propertyNameMaps[i]; string positionNameInIBufferable = positionNameInIBufferables[i]; var highlightRenderer = new HighlightRenderer( bufferable, positionNameInIBufferable); highlightRenderer.Name = string.Format("Highlight: [{0}]", key); highlightRenderer.Initialize(); var pickableRenderer = new PickableRenderer( bufferable, shaders, propertyNameMap, positionNameInIBufferable); pickableRenderer.Name = string.Format("Pickable: [{0}]", key); pickableRenderer.Initialize(); if (i > 2) { pickableRenderer.SetUniform("normalLength", 0.5f); pickableRenderer.SetUniform("showModel", true); pickableRenderer.SetUniform("showNormal", false); } HighlightedPickableRenderer renderer = new HighlightedPickableRenderer( highlightRenderer, pickableRenderer); renderer.Initialize(); { GLSwitch lineWidthSwitch = new LineWidthSwitch(5); pickableRenderer.SwitchList.Add(lineWidthSwitch); GLSwitch pointSizeSwitch = new PointSizeSwitch(10); pickableRenderer.SwitchList.Add(pointSizeSwitch); GLSwitch polygonModeSwitch = new PolygonModeSwitch(PolygonModes.Filled); pickableRenderer.SwitchList.Add(polygonModeSwitch); //GLSwitch blendSwitch = new BlendSwitch(); //pickableRenderer.SwitchList.Add(blendSwitch); } this.rendererDict.Add(key, renderer); } this.SelectedModel = GeometryModel.Tetrahedron; } { var frmBulletinBoard = new FormBulletinBoard(); //frmBulletinBoard.Dump = true; frmBulletinBoard.Show(); this.pickedGeometryBoard = frmBulletinBoard; } { var UIRoot = new UIRoot(); UIRoot.Initialize(); this.uiRoot = UIRoot; var uiAxis = new UIAxis(AnchorStyles.Left | AnchorStyles.Bottom, new Padding(3, 3, 3, 3), new Size(128, 128), -100, 100); uiAxis.Initialize(); UIRoot.Children.Add(uiAxis); this.uiAxis = uiAxis; var font = new Font("Courier New", 32); var uiText = new UIText(AnchorStyles.Left | AnchorStyles.Bottom, new Padding(0, 0, 0, 0), new Size(250, 20), -100, 100, font.GetFontBitmap("[index: 0123456789]").GetFontTexture()); uiText.Text = ""; uiRoot.Children.Add(uiText); this.uiText = uiText; } { var frmPropertyGrid = new FormProperyGrid(this.rendererDict[this.SelectedModel].PickableRenderer); frmPropertyGrid.Show(); this.pickableRendererPropertyGrid = frmPropertyGrid; } { var frmPropertyGrid = new FormProperyGrid(this.rendererDict[this.SelectedModel].Highlighter); frmPropertyGrid.Show(); this.highlightRendererPropertyGrid = frmPropertyGrid; } { var frmPropertyGrid = new FormProperyGrid(this); frmPropertyGrid.Show(); this.formPropertyGrid = frmPropertyGrid; } { var frmPropertyGrid = new FormProperyGrid(this.uiText); frmPropertyGrid.Show(); } { var frmIndexBufferPtrBoard = new FormIndexBufferPtrBoard(); frmIndexBufferPtrBoard.SetTarget(this.rendererDict[this.SelectedModel].PickableRenderer.IndexBufferPtr); frmIndexBufferPtrBoard.Show(); this.frmIndexBufferPtrBoard = frmIndexBufferPtrBoard; } }