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.


Messages - Raptor2277

Pages: [1] 2
1
DotNet / Re: OpenTK and SFML
« on: May 21, 2016, 03:44:42 am »
Welp, thanks for the help. Interesting issue we got here.

2
DotNet / Re: OpenTK and SFML
« on: May 19, 2016, 06:47:40 pm »
It crashes on the first(ish) GL.* call. Int his calse it was GL. Clear(), the other case I had was GL.TexImage2D. I have a GTX 970 with 365.19. I am also using the dlls handed by SFML.NET

3
DotNet / Re: OpenTK and SFML
« on: May 19, 2016, 07:11:21 am »
I tried you code(pasted) and replaced you context creation with what I originally had. It shows the cube for a split second, then it goes away. I guess its the context creation that is messing me up. I just can't find much on why its giving me that error.

4
DotNet / Re: OpenTK and SFML
« on: May 19, 2016, 07:06:37 am »
I get a an AccessViolcationException when I use


            Toolkit.Init();
            OpenTK.Graphics.GraphicsContext context = new OpenTK.Graphics.GraphicsContext(ContextHandle.Zero, OpenTK.Platform.Utilities.CreateWindowsWindowInfo(win.SystemHandle));
            context.LoadAll();

 


this is the exact error:
An unhandled exception of type 'System.AccessViolationException' occurred in OpenTK.dll

Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

This issue is disused in http://en.sfml-dev.org/forums/index.php?topic=18276.0 forum. This is the only way I found to solve that problem.

5
DotNet / Re: OpenTK and SFML
« on: May 18, 2016, 05:53:34 am »
Without the

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

 

It draws the cube, rotated so an edge faces the screen.

6
DotNet / Re: OpenTK and SFML
« on: May 18, 2016, 05:52:21 am »
Here is the full code. Adding the -4 translation didn't do anything.


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);
                GL.MatrixMode(MatrixMode.Projection);
                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);

            #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, 000);

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

                //win.Clear();
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

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

                GL.MatrixMode(MatrixMode.Modelview);
                GL.LoadIdentity();
                GL.Translate(0, 0, -4);
                GL.Rotate(50f, 0, 1, 0);

                GL.DrawArrays(OpenTK.Graphics.OpenGL.PrimitiveType.Triangles, 0, verts.Length);

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

                win.Display();
            }
        }
    }
}


 

7
DotNet / Re: OpenTK and SFML
« on: May 16, 2016, 11:46:23 pm »
Just do clarify, I draw the cube without trying to draw the text and it draws the cube fine, it rotates, all is good. But as soon as I do win.Draw(t); (drawing the text), the cube disappears.

8
DotNet / Re: OpenTK and SFML
« on: May 16, 2016, 11:43:58 pm »
I've changed that, that was left over when I was doing immediate drawing. Calling GL.CLear() or window.clear() doesnt seem to make a difference.

9
DotNet / Re: OpenTK and SFML
« on: May 16, 2016, 08:44:38 pm »
 Thanks, the resizing works now. That's a dumb mistake by me. But trying to render the text now doesn't draw the  cube. I've tried resetting the model-view and projection on each draw, but that doesn't work either.

10
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();
            }
        }
    }
}


 

11
Graphics / Re: Text.GetGlobalBounds() is lying to me!
« on: October 06, 2015, 12:14:05 am »
It's kinda weird how it works. It is implemented weirdly. If you do it normally.
t.CharacterSize = 100;
t.Position = new Vector2f(200, 200);
...
...
Draw.drawRectangle(w, gBounds, Color.Yellow);
w.Draw(new Vertex[] { new Vertex(new Vector2f(0, 200), Color.White), new Vertex(new Vector2f(900, 200), Color.White) }, PrimitiveType.Lines);
w.Draw(t);
 

And here is what it looks like. As you can see there is some white space at the top. And the getGlobalBounds() returns not 200, 200 but 201, 224. That's because of the empty space at the top. If you notice the getLocanBounds() x and y are 1, 24. So you can use that to position it properly. IDK why the it doesn't do it right the first time.


Here is what I use to position it properly.
t.CharacterSize = 100;
setPosition(t, new Vector2f(200, 200));
...
...
public void setPosition(Text text, Vector2f pos)
{
     Vector2f offsets = new Vector2f(text.GetLocalBounds().Left, text.GetLocalBounds().Top);

     text.Position = new Vector2f(pos.X - offsets.X, pos.Y - offsets.Y);
}
 

And here is what it looks like.

12
Graphics / Re: SFML.Net, Failed to compile Fragement Shader error(#60)
« on: August 28, 2015, 05:21:48 pm »
I have made it work.

It turns out that it might be an encoding problem. What I did is create a new text document on the computer that I'm trying to make it work on and copy the contents of the shader there. Then I "save as" replacing the original shader. It loads fine with no errors.

The problem is I don't know anything about encoding. If someone could point me in the right direction how to write and safe shaders in a way that it will work on all platforms.

Thank you all for your help.

13
Graphics / Re: SFML.Net, Failed to compile Fragement Shader error(#60)
« on: August 27, 2015, 04:17:35 am »
The computer supports shaders because I've had in not compile once because one didn't support shaders. It gave an error before it even began compiling.

I've also tried some debugging like reading the file and outputting it to cmd before trying to create the shader class. It reads fine and prints the contents of the txt file fine.

14
Graphics / Re: SFML.Net, Failed to compile Fragement Shader error(#60)
« on: August 26, 2015, 10:47:39 pm »
It is.

15
Graphics / Re: SFML.Net, Failed to compile Fragement Shader error(#60)
« on: August 26, 2015, 06:36:35 pm »
Here is the shader.

uniform vec2 lightPos;
uniform vec3 lightColor;
uniform float screenHeight;

uniform sampler2D texture;

void main()
{   
   lightPos.y = screenHeight - lightPos.y;
   float length = length(lightPos - gl_FragCoord.xy);
   float attenuation = 1.0 / (length/10) + .2;

   vec4 color2 = vec4(lightColor, 1) * attenuation;
   
   vec4 color = texture2D(texture,gl_TexCoord[0].st);

   if(color == vec4(0,0,0,1))
      gl_FragColor = color;
   else
      gl_FragColor = color2;

}

Pages: [1] 2
anything