Alright, I got it working over here.
using System;using SFML.Window;using SFML.Graphics;using OpenTK;using OpenTK.Graphics.OpenGL;namespace SFML
.NET_2015{ class Program
{ static void Main
(string[] args
) { ContextSettings contextSettings
= new ContextSettings
(24,
0,
0); 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
= Matrix4
.CreatePerspectiveFieldOfView((float)Math
.PI * 50f
/ 180f, win
.Size.X / (float)win
.Size.Y,
.1f, 10f
); GL
.LoadMatrix(ref matr
); }; Toolkit
.Init(); OpenTK
.Graphics.GraphicsContext context
= new OpenTK
.Graphics.GraphicsContext(ContextHandle
.Zero, OpenTK
.Platform.Utilities.CreateWindowsWindowInfo(win
.SystemHandle)); 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
.BindBuffer(BufferTarget
.ArrayBuffer,
0); Text t
= new Text
("Hello Cube",
new Font
("arial.ttf")); t
.Position = new System.Vector2f(200,
0); while (win
.IsOpen) { win
.DispatchEvents(); win
.Clear(); GL
.Viewport(0,
0,
(int)win
.Size.X,
(int)win
.Size.Y); GL
.MatrixMode(MatrixMode
.Projection); Matrix4 matr
= 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
.BindBuffer(BufferTarget
.ArrayBuffer, buff
); GL
.VertexPointer(3, VertexPointerType
.Float,
3 * sizeof(float),
0); GL
.DrawArrays(OpenTK
.Graphics.OpenGL.PrimitiveType.Triangles,
0, verts
.Length); GL
.BindBuffer(BufferTarget
.ArrayBuffer,
0); win
.PushGLStates(); win
.Draw(t
); win
.PopGLStates(); win
.Display(); } } }} Two things:
You were having two contexts: one from SFML, and the one you created with OpenTK. Apparently, passing
ContextHandle.Zero to the
GraphicsContext constructor makes OpenTK find the already-existing context (from SFML in this case). A little nicer than manually doing so with a P/Invoke to
wglGetCurrentContext (What I did in the first place!). I'm not certain if this was the issue (or part of it), but I could see it potentially causing complications in the future.
The part I am certain was at least part of the issue was coming from your cube's vertex buffer still being bound when SFML tries to draw. I haven't ever dug through enough of SFML's internals to know what it does that would make this an issue, but, in the future, make sure to unbind your buffers (pass 0 as the buffer id for
glBindBuffer) before drawing with SFML (and can be a good thing to do anyways).
Beyond that, I think that was all I changed!
PS: You can also move your projection and view matrix code out of your while loop, and before it now, if you wish:
using System;using SFML.Window;using SFML.Graphics;using OpenTK;using OpenTK.Graphics.OpenGL;namespace SFML
.NET_2015{ class Program
{ static void Main
(string[] args
) { ContextSettings contextSettings
= new ContextSettings
(24,
0,
0); 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
= Matrix4
.CreatePerspectiveFieldOfView((float)Math
.PI * 50f
/ 180f, win
.Size.X / (float)win
.Size.Y,
.1f, 10f
); GL
.LoadMatrix(ref matr
); }; Toolkit
.Init(); OpenTK
.Graphics.GraphicsContext context
= new OpenTK
.Graphics.GraphicsContext(ContextHandle
.Zero, OpenTK
.Platform.Utilities.CreateWindowsWindowInfo(win
.SystemHandle)); 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
.BindBuffer(BufferTarget
.ArrayBuffer,
0); GL
.Viewport(0,
0,
(int)win
.Size.X,
(int)win
.Size.Y); GL
.MatrixMode(MatrixMode
.Projection); Matrix4 matp
= Matrix4
.CreatePerspectiveFieldOfView((float)Math
.PI * 50f
/ 180f, win
.Size.X / (float)win
.Size.Y,
.1f, 10f
); GL
.LoadMatrix(ref matp
); GL
.MatrixMode(MatrixMode
.Modelview); GL
.LoadIdentity(); GL
.Translate(0,
0,
-4); GL
.Rotate(50f,
0,
1,
0); Text t
= new Text
("Hello Cube",
new Font
("arial.ttf")); t
.Position = new System.Vector2f(200,
0); while (win
.IsOpen) { win
.DispatchEvents(); win
.Clear(); GL
.BindBuffer(BufferTarget
.ArrayBuffer, buff
); GL
.VertexPointer(3, VertexPointerType
.Float,
3 * sizeof(float),
0); GL
.DrawArrays(OpenTK
.Graphics.OpenGL.PrimitiveType.Triangles,
0, verts
.Length); GL
.BindBuffer(BufferTarget
.ArrayBuffer,
0); win
.PushGLStates(); win
.Draw(t
); win
.PopGLStates(); win
.Display(); } } }}