Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Raptor2277

Pages: [1]
1
DotNet / OpenTK and SFML
« on: May 14, 2016, 11:17:50 pm »
Having a hard time getting sfml to work with opentk. I am creating an sfml window and trying to draw a 3d cube using opengl while using sfml's Text classes to draw text on top. However, on window.resize it bugs the program out. I am changing the model-view and setting the view-port, then it bugs the program where the cube is no longer being drawn. Also when I try to render Text, it is really buggy and flashy.

Am I doing something fundamentally wrong here?


using System;
using SFML.Window;
using SFML.Graphics;
using OpenTK.Graphics.OpenGL;
using OpenTK;

namespace SFML.NET_2015
{
    class Program
    {
        static void Main(string[] args)
        {
            ContextSettings contextSettings = new ContextSettings(24, 0, 0);
            SFML.Graphics.RenderWindow win = new RenderWindow(new VideoMode(640, 400), "SFML.NET", Styles.Default, contextSettings);
            win.SetFramerateLimit(144);
            win.SetMouseCursorVisible(true);

            win.Closed += (o, e) => { win.Close(); };
            win.Resized += (o, e) =>
            {
                GL.Viewport(0, 0, (int)win.Size.X, (int)win.Size.Y);
                Matrix4 matr = OpenTK.Matrix4.CreatePerspectiveFieldOfView((float)Math.PI * 50f / 180f, win.Size.X / (float)win.Size.Y, .1f, 10f);
                GL.LoadMatrix(ref matr);
            };


            Toolkit.Init();
            OpenTK.Graphics.GraphicsMode graphicsMode = new OpenTK.Graphics.GraphicsMode(32, (int)contextSettings.DepthBits, (int)contextSettings.StencilBits, (int)contextSettings.AntialiasingLevel);
            OpenTK.Platform.IWindowInfo windowInfo = OpenTK.Platform.Utilities.CreateWindowsWindowInfo(win.SystemHandle);
            OpenTK.Graphics.GraphicsContext context = new OpenTK.Graphics.GraphicsContext(graphicsMode, windowInfo);
            context.MakeCurrent(windowInfo);
            context.LoadAll();

            GL.EnableClientState(ArrayCap.VertexArray);

            GL.MatrixMode(MatrixMode.Projection);
            Matrix4 mat = OpenTK.Matrix4.CreatePerspectiveFieldOfView((float)Math.PI * 50f / 180f, win.Size.X / (float)win.Size.Y, .1f, 10f);
            GL.LoadMatrix(ref mat);

            GL.MatrixMode(MatrixMode.Modelview);
            GL.Translate(0, 0, -4);

            #region Verts
            float[] verts =
            {
                -1.0f,-1.0f,-1.0f, // triangle 1 : begin
    -1.0f,-1.0f, 1.0f,
    -1.0f, 1.0f, 1.0f, // triangle 1 : end
    1.0f, 1.0f,-1.0f, // triangle 2 : begin
    -1.0f,-1.0f,-1.0f,
    -1.0f, 1.0f,-1.0f, // triangle 2 : end
    1.0f,-1.0f, 1.0f,
    -1.0f,-1.0f,-1.0f,
    1.0f,-1.0f,-1.0f,
    1.0f, 1.0f,-1.0f,
    1.0f,-1.0f,-1.0f,
    -1.0f,-1.0f,-1.0f,
    -1.0f,-1.0f,-1.0f,
    -1.0f, 1.0f, 1.0f,
    -1.0f, 1.0f,-1.0f,
    1.0f,-1.0f, 1.0f,
    -1.0f,-1.0f, 1.0f,
    -1.0f,-1.0f,-1.0f,
    -1.0f, 1.0f, 1.0f,
    -1.0f,-1.0f, 1.0f,
    1.0f,-1.0f, 1.0f,
    1.0f, 1.0f, 1.0f,
    1.0f,-1.0f,-1.0f,
    1.0f, 1.0f,-1.0f,
    1.0f,-1.0f,-1.0f,
    1.0f, 1.0f, 1.0f,
    1.0f,-1.0f, 1.0f,
    1.0f, 1.0f, 1.0f,
    1.0f, 1.0f,-1.0f,
    -1.0f, 1.0f,-1.0f,
    1.0f, 1.0f, 1.0f,
    -1.0f, 1.0f,-1.0f,
    -1.0f, 1.0f, 1.0f,
    1.0f, 1.0f, 1.0f,
    -1.0f, 1.0f, 1.0f,
    1.0f,-1.0f, 1.0f
            };
            #endregion

            int buff = GL.GenBuffer();
            GL.BindBuffer(BufferTarget.ArrayBuffer, buff);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(verts.Length * sizeof(float)), verts, BufferUsageHint.StaticDraw);

            GL.VertexPointer(3, VertexPointerType.Float, 3 * sizeof(float), 0);

            Text t = new Text("Hello Cube", new Font("andyb.ttf"));
            t.Position = new System.Vector2f(200, 200);

            while (win.IsOpen)
            {
                win.DispatchEvents();

                GL.Rotate(.1f, 0, 1, 0);
                GL.DrawArrays(OpenTK.Graphics.OpenGL.PrimitiveType.Triangles, 0, verts.Length);
                GL.End();

                win.PushGLStates();
                win.Draw(t);
                win.PopGLStates();

                win.Display();
            }
        }
    }
}


 

2
Graphics / SFML.Net, Failed to compile Fragement Shader error(#60)
« on: August 26, 2015, 06:01:05 pm »
It runs fine on my computer and some of my friends' computers. But when I try it on others, I get this error.

Failed to compile fragment shader:
Fragment shader failed to compile with the following erros:
ERROR: error(#60) Unknown char: ""
ERROR: error(#273) 1 compilation erros. No code generated

Thnks in advance.

Pages: [1]