当前位置: 首页>>代码示例>>C#>>正文


C# OpenGL.GetInteger方法代码示例

本文整理汇总了C#中SharpGL.OpenGL.GetInteger方法的典型用法代码示例。如果您正苦于以下问题:C# OpenGL.GetInteger方法的具体用法?C# OpenGL.GetInteger怎么用?C# OpenGL.GetInteger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SharpGL.OpenGL的用法示例。


在下文中一共展示了OpenGL.GetInteger方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Render

		public override void Render(OpenGL gl, RenderMode renderMode)
		{
			//	Do the ordinary polygon drawing.
			base.Render(gl, renderMode);

			//	Now we do our own.
            PushGeometricTransformation(gl);

			//	Get the viewport.
			int[] viewport = new int[4];
            gl.GetInteger(OpenGL.GL_VIEWPORT, viewport);

			int index = 0;
			
			//	Here we're going to go through every vertex..
			foreach(Vertex vertex in Vertices)
			{
				//	Convert the vertex into a coord.
				Vertex screen = gl.Project(vertex);

				//	Get the OpenGL coord as a GDI coord.
				float x = screen.X;
				float y = viewport[3] - screen.Y;
				
				/*todoif(gl.GDIGraphics != null)
				{
					//	Label the vertex.
					gl.GDIGraphics.DrawString(index.ToString(),	new System.Drawing.Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold),
						Brushes.Red, new PointF(x, y));
				}*/

				index++;
			}

			PopGeometricTransformation(gl);
		}
开发者ID:chantsunman,项目名称:sharpgl,代码行数:36,代码来源:BuildablePolygon.cs

示例2: DrawText

        /// <summary>
        /// Draws the text.
        /// </summary>
        /// <param name="gl">The gl.</param>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        /// <param name="r">The r.</param>
        /// <param name="g">The g.</param>
        /// <param name="b">The b.</param>
        /// <param name="faceName">Name of the face.</param>
        /// <param name="fontSize">Size of the font.</param>
        /// <param name="text">The text.</param>
        public void DrawText(OpenGL gl, int x, int y, float r, float g, float b, string faceName, float fontSize, string text)
        {
            //  Get the font size in pixels.
            var fontHeight = (int)(fontSize * (16.0f / 12.0f));

            //  Do we have a font bitmap entry for this OpenGL instance and face name?
            var result = (from fbe in fontBitmapEntries
                         where fbe.HDC == gl.RenderContextProvider.DeviceContextHandle
                         && fbe.HRC == gl.RenderContextProvider.RenderContextHandle
                         && String.Compare(fbe.FaceName, faceName, StringComparison.OrdinalIgnoreCase) == 0
                         && fbe.Height == fontHeight
                         select fbe).ToList();

            //  Get the FBE or null.
            var fontBitmapEntry = result.FirstOrDefault();

            //  If we don't have the FBE, we must create it.
            if (fontBitmapEntry == null)
                fontBitmapEntry = CreateFontBitmapEntry(gl, faceName, fontHeight);

            double width = gl.RenderContextProvider.Width;
            double height = gl.RenderContextProvider.Height;
            
            //  Create the appropriate projection matrix.
            gl.MatrixMode(OpenGL.GL_PROJECTION);
            gl.PushMatrix();
            gl.LoadIdentity();
            
            int[] viewport = new int[4];
            gl.GetInteger(OpenGL.GL_VIEWPORT, viewport);
            gl.Ortho(0, width, 0, height, -1, 1);

            //  Create the appropriate modelview matrix.
            gl.MatrixMode(OpenGL.GL_MODELVIEW);
            gl.PushMatrix();
            gl.LoadIdentity();
            gl.Color(r, g, b);
            gl.RasterPos(x, y);

            gl.PushAttrib(OpenGL.GL_LIST_BIT | OpenGL.GL_CURRENT_BIT |
                OpenGL.GL_ENABLE_BIT | OpenGL.GL_TRANSFORM_BIT);
            gl.Color(r, g, b);
            gl.Disable(OpenGL.GL_LIGHTING);
            gl.Disable(OpenGL.GL_TEXTURE_2D);
            gl.Disable(OpenGL.GL_DEPTH_TEST);
            gl.RasterPos(x, y);

            //  Set the list base.
            gl.ListBase(fontBitmapEntry.ListBase);

            //  Create an array of lists for the glyphs.
            var lists = text.Select(c => (byte) c).ToArray();

            //  Call the lists for the string.
            gl.CallLists(lists.Length, lists);
            gl.Flush();
            
            //  Reset the list bit.
            gl.PopAttrib();

            //  Pop the modelview.
            gl.PopMatrix();

            //  back to the projection and pop it, then back to the model view.
            gl.MatrixMode(OpenGL.GL_PROJECTION);
            gl.PopMatrix();
            gl.MatrixMode(OpenGL.GL_MODELVIEW);
        }
开发者ID:hhool,项目名称:sharpgl,代码行数:80,代码来源:FontOutlines.cs

示例3: IntialiseFromSerial

        /// <summary>
        /// Call this function to iniatilise a scene loaded from a file.
        /// </summary>
        /// <param name="ctrl">The OpenGLCtrl.</param>
        /// <param name="sceneType">The scene type.</param>
        public virtual void IntialiseFromSerial(int width, int height, SceneType sceneType)
        {
            //	Create OpenGL.
            gl = new OpenGL();
            gl.Create(width, height);

            //	Find out how many lights OpenGL can support.
            int [] umaxlights = new int[1];
            gl.GetInteger(OpenGL.MAX_LIGHTS, umaxlights);

            //	Re-create as many openGL lights as we can.
            for(uint u = 0; u < umaxlights[0]; u++)
            {
                if(u < Lights.Count)
                {
                    Light light = lights[(int)u];
                    light.GLCode = OpenGL.LIGHT0 + u;
                }
            }

            //	Re-create all the quadrics
            foreach(Quadric quadric in quadrics)
                quadric.Create(gl);

            //	Set the scene type.
            SetSceneType(sceneType);

            //	Initialise stock drawing.
            gl.InitialiseStockDrawing();

            //	Set the Scene OpenGL for the quadrics.
            Quadric.SceneOpenGL = OpenGL;
        }
开发者ID:nromik,项目名称:sharpgl,代码行数:38,代码来源:Scene.cs

示例4: Create

        /// <summary>
        /// This function creates the texture from an image file.
        /// </summary>
        /// <param name="gl">The OpenGL object.</param>
        /// <param name="path">The path to the image file.</param>
        /// <returns>True if the texture was successfully loaded.</returns>
        public virtual bool Create(OpenGL gl, string path)
        {
            //  Create the underlying OpenGL object.
            Create(gl);

            //  Try and load the bitmap. Return false on failure.
            Bitmap image = new Bitmap(path);
            if (image == null)
                return false;

            //	Get the maximum texture size supported by OpenGL.
            int[] textureMaxSize = { 0 };
            gl.GetInteger(OpenGL.GL_MAX_TEXTURE_SIZE, textureMaxSize);

            //	Find the target width and height sizes, which is just the highest
            //	posible power of two that'll fit into the image.
            int targetWidth = textureMaxSize[0];
            int targetHeight = textureMaxSize[0];

            for (int size = 1; size <= textureMaxSize[0]; size *= 2)
            {
                if (image.Width < size)
                {
                    targetWidth = size / 2;
                    break;
                }
                if (image.Width == size)
                    targetWidth = size;

            }

            for (int size = 1; size <= textureMaxSize[0]; size *= 2)
            {
                if (image.Height < size)
                {
                    targetHeight = size / 2;
                    break;
                }
                if (image.Height == size)
                    targetHeight = size;
            }

            //  If need to scale, do so now.
            if (image.Width != targetWidth || image.Height != targetHeight)
            {
                //  Resize the image.
                Image newImage = image.GetThumbnailImage(targetWidth, targetHeight, null, IntPtr.Zero);

                //  Destory the old image, and reset.
                image.Dispose();
                image = (Bitmap)newImage;
            }

            //  Create an array of pixels the correct size.
            pixelData = new byte[image.Width * image.Height * 4];
            int index = 0;

            //  TODO: The loop below is staggeringly slow and needs speeding up.
            //  Go through the pixels backwards, this seems to be how OpenGL wants the data.
            for (int y = image.Height - 1; y >= 0; y--)
            {
                for (int x = 0; x < image.Width; x++)
                {
                    Color pixel = image.GetPixel(x, y);
                    pixelData[index++] = pixel.R;
                    pixelData[index++] = pixel.G;
                    pixelData[index++] = pixel.B;
                    pixelData[index++] = pixel.A;
                }
            }

            //	Set the width and height.
            width = image.Width;
            height = image.Height;

            //  Dispose of the image file.
            image.Dispose();

            //	Bind our texture object (make it the current texture).
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, TextureName);

            //  Set the image data.
            gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, (int)OpenGL.GL_RGBA,
                width, height, 0, OpenGL.GL_RGBA, OpenGL.GL_UNSIGNED_BYTE,
                pixelData);

            //  Set linear filtering mode.
            gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR);
            gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_LINEAR);

            //  We're done!
            return true;
        }
开发者ID:Kontrast,项目名称:Computer-Graphics,代码行数:99,代码来源:Texture.cs

示例5: BeforeRendering

        protected void BeforeRendering(OpenGL gl, RenderMode renderMode)
        {
            IScientificCamera camera = this.camera;
            if (camera != null)
            {
                if (camera.CameraType == CameraTypes.Perspecitive)
                {
                    IPerspectiveViewCamera perspective = camera;
                    this.projectionMatrix = perspective.GetProjectionMat4();
                    this.viewMatrix = perspective.GetViewMat4();
                }
                else if (camera.CameraType == CameraTypes.Ortho)
                {
                    IOrthoViewCamera ortho = camera;
                    this.projectionMatrix = ortho.GetProjectionMat4();
                    this.viewMatrix = ortho.GetViewMat4();
                }
                else
                { throw new NotImplementedException(); }
            }

            modelMatrix = glm.scale(mat4.identity(), new vec3(1, 1, this.ZAxisScale));

            gl.Enable(OpenGL.GL_VERTEX_PROGRAM_POINT_SIZE);
            gl.Enable(OpenGL.GL_POINT_SPRITE_ARB);
            gl.TexEnv(OpenGL.GL_POINT_SPRITE_ARB, OpenGL.GL_COORD_REPLACE_ARB, OpenGL.GL_TRUE);
            gl.Enable(OpenGL.GL_POINT_SMOOTH);
            gl.Hint(OpenGL.GL_POINT_SMOOTH_HINT, OpenGL.GL_NICEST);
            gl.Enable(OpenGL.GL_BLEND);
            gl.BlendEquation(OpenGL.GL_FUNC_ADD_EXT);
            gl.BlendFuncSeparate(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA, OpenGL.GL_ONE, OpenGL.GL_ONE);

            ShaderProgram shaderProgram = this.shaderProgram;
            int[] viewport = new int[4];
            gl.GetInteger(OpenGL.GL_VIEWPORT, viewport);

            shaderProgram.Bind(gl);
            shaderProgram.SetUniformMatrix4(gl, "projectionMatrix", projectionMatrix.to_array());
            shaderProgram.SetUniformMatrix4(gl, "viewMatrix", viewMatrix.to_array());
            shaderProgram.SetUniformMatrix4(gl, "modelMatrix", modelMatrix.to_array());
            shaderProgram.SetUniform1(gl, "canvasWidth", viewport[2] + 0.0f);
            shaderProgram.SetUniform1(gl, "canvasHeight", viewport[3] + 0.0f);
            shaderProgram.SetUniform1(gl, "opacity", this.Opacity);

            this.texture.Bind(gl);
            shaderProgram.SetUniform1(gl, "tex", this.texture.TextureName);
            shaderProgram.SetUniform1(gl, "brightness", this.Brightness);
        }
开发者ID:bitzhuwei,项目名称:CSharpGL,代码行数:48,代码来源:PointGrid.cs

示例6: DrawText

        /// <summary>
        /// Draws the text.
        /// </summary>
        /// <param name="gl">The gl.</param>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        /// <param name="r">The r.</param>
        /// <param name="g">The g.</param>
        /// <param name="b">The b.</param>
        /// <param name="faceName">Name of the face.</param>
        /// <param name="fontSize">Size of the font.</param>
        /// <param name="text">The text.</param>
        public void DrawText(OpenGL gl, int x, int y, float r, float g, float b, string faceName, float fontSize, string text)
        {
            //  Get the font size in pixels.
            int fontHeight = (int)(fontSize * (16.0f / 12.0f));

            //  Do we have a font bitmap entry for this OpenGL instance and face name?
            var result = from fbe in fontBitmapEntries
                         where fbe.HDC == gl.RenderContextProvider.DeviceContextHandle
                         && fbe.HRC == gl.RenderContextProvider.RenderContextHandle
                         && string.Compare(fbe.FaceName, faceName, true) == 0
                         && fbe.Height == fontHeight
                         select fbe;

            //  Get the FBE or null.
            FontBitmapEntry fontBitmapEntry = result == null || result.Count() == 0 ? null : result.First();

            //  If we don't have the FBE, we must create it.
            if (fontBitmapEntry == null)
                fontBitmapEntry = CreateFontBitmapEntry(gl, faceName, fontHeight);

            double width = gl.RenderContextProvider.Width;
            double height = gl.RenderContextProvider.Height;

            double aspect_ratio = width / height;
            
            //  Create the appropriate projection matrix.
            gl.MatrixMode(OpenGL.GL_PROJECTION);
            gl.PushMatrix();
            gl.LoadIdentity();
            
            int[] viewport = new int[4];
            gl.GetInteger(OpenGL.GL_VIEWPORT, viewport);
            //gl.Ortho2D(viewport[0], viewport[2], viewport[1], viewport[3]);
            gl.Ortho(0, width, 0, height, -1, 1);

            //  Create the appropriate modelview matrix.
            gl.MatrixMode(OpenGL.GL_MODELVIEW);
            gl.PushMatrix();
            gl.LoadIdentity();
            //gl.Translate(0, 0, -5);
            //gl.RasterPos(x, y);
            gl.Color(r, g, b);
            gl.RasterPos(x, y);

            gl.PushAttrib(OpenGL.GL_LIST_BIT | OpenGL.GL_CURRENT_BIT |
                OpenGL.GL_ENABLE_BIT | OpenGL.GL_TRANSFORM_BIT);
            gl.Color(r, g, b);
            gl.Disable(OpenGL.GL_LIGHTING);
            gl.Disable(OpenGL.GL_TEXTURE_2D);
            gl.Disable(OpenGL.GL_DEPTH_TEST);
            gl.RasterPos(x, y);
           /** gl.Enable(OpenGL.GL_BLEND);
            gl.BlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA); */

            //  Set the list base.
            gl.ListBase(fontBitmapEntry.ListBase);

            //  Create an array of lists for the glyphs.
            List<byte> lists = new List<byte>();
            foreach(char c in text)
                lists.Add((byte)c);            

            //  Call the lists for the string.
            gl.CallLists(lists.Count, lists.ToArray());
            gl.Flush();
            
            //  Reset the list bit.
            gl.PopAttrib();

            //  Pop the modelview.
            gl.PopMatrix();

            //  back to the projection and pop it, then back to the model view.
            gl.MatrixMode(OpenGL.GL_PROJECTION);
            gl.PopMatrix();
            gl.MatrixMode(OpenGL.GL_MODELVIEW);
        }
开发者ID:mind0n,项目名称:hive,代码行数:89,代码来源:FontOutlines.cs


注:本文中的SharpGL.OpenGL.GetInteger方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。