With OpenTK and VB.NET, how to use GLControl with OpenGL 3.x features? - vb.net

I'm using OpenTK with rendering through a GLControl. However, I cannot find any examples on the internet or figure out how to use OpenGL 3.x features (Disregarding the short mention in the OpenTK FAQ, which wasn't overly helpful).
By OpenGL 3.x features, I'm meaning that the whole 'glTranslate' model is unaccessible, and the only rendering or translation, etc, is used through shaders and passing around model/view/projection matrices.

GLControl by default creates a compatibility context with the maximum version supported by your drivers. For example, if you have a recent Nvidia card with up-to-date drivers, GLControl will give you an OpenGL 4.5 compatibility context.
Note that on Linux and Mac OS X, compatibility contexts are limited to OpenGL 2.1. To access higher versions you need to create a core context instead:
var glControl = new GLControl(GraphicsMode.Default, 4, 0, GraphicsContextFlags.ForwardCompatible);
Deprecated functions, such as glTranslate, are not available on core contexts.
If you are using the WinForms UI designer, you can achieve the same result by deriving a custom control from GLControl and specifying the desired (minimum) version in its constructor:
class CoreGLControl : GLControl
{
public CoreGLControl() : base(GraphicsMode.Default, 3, 0, GraphicsContextFlags.ForwardCompatible)
{ }
}
You can then drag and drop this onto your form.

Related

SharpDX 'No such interface supported'

I came across this post here C# Which is the fastest way to take a screen shot?
and am trying to implement the answer that utilizes SharpDX. It appears to run fine on Windows 10, however, it crashes on Windows 7. The error it gives is:
Unhandled Exception: SharpDX.SharpDXException: HRESULT: [0x800004002], Module: [General],
ApiCode: [E_NOINTERFACE/No such interface supported], Message No such interface supported
And the stack trace it points to...
var factory = new Factory1();
var adapter = factory.GetAdapter1(0);
var device = new SharpDX.Direct3D11.Device(adapter);
var output = adapter.GetOutput(0);
var output1 = output.QueryInterface<Output1>();
Happens at output1 line where it does the QueryInterface. I don't know a whole lot about graphics drivers, but is this an issue with the DirectX11 configuration? Or is this something inherent to Windows 7?
SharpDX is nothing more than a thin managed code wrapper around the native C/C++ COM interface for Direct3D. As such, all the information you need can be found in the Direct3D documentation on MSDN. I would highly recommend reading through whatever you can find there, as almost all of the restrictions and caveats apply to SharpDX.
Now, the code you have is doing the following:
1) Creating a DXGI 1.1 Factory interface (IDXGIFactory1).
2) Getting a DXGI 1.1 Adapter interface for the first graphics adapter (IDXGIAdapter1).
3) Creating a Direct3D 11 Device interface from the aforementioned adapter (ID3D11Device).
4) Getting the first output from the adapter interface (IDXGIOutput).
5) Querying for the DXGI 1.1 Output interface (IDXGIOutput1) from the DXGI 1.0 Output interface.
The last step of this process is the point where things fail. This is because the interface you're asking for (IDXGIOutput1) is not supported on standard Windows 7 - it requires Windows 8+ or Windows 7 with the Platform Update. You can see that in the Requirements portion of the IDXGIOutput1 documentation on MSDN.
Again, I would highly recommend you familiarize yourself with the C/C++ interfaces defined by Direct3D if you plan to do any further work with DirectX or SharpDX.

Is it true that OpenGL VBO should not be used for devices running Android 2.2 (Froyo)?

Is this a joke? I hope it is because I hear VBO is the way to go and I want to use it from now on.
As Reto Koradi explained, 2.2 has VBO support but no Java bindings. To use VBO on 2.2 you can use GLES20Fix bridge from official GDC11 demo: https://code.google.com/p/gdc2011-android-opengl/
However, 2.2 is almost completely extinct now so you can just use minimum API level 9. Stats of currently used Android versions: http://developer.android.com/about/dashboards/index.html
That's sort of true, at least if you're using the Java APIs. OpenGL ES 2.0, which includes VBO support, was added with API level 8, which corresponds to 2.2 (Froyo).
But they initially forgot to include a proper Java binding for the key entry point needed for VBO support. It ended up getting added in API level 9, which corresponds to 2.3 (Gingerbread). So in Froyo, you can use VBOs from native code with the NDK, but not with the Java bindings. The native bindings for ES 2.0 were actually there even before Froyo, I remember using them in Éclair.
You can see this by looking at the GLES20 documentation, it says "Added in API level 8".
But if you look at the small print next to the glVertexAttribPointer() call that takes an int as its last argument, it says that it was introduced with API level 9 (direct documentation link).

Drawing primitive geometry in OpenTK?

I am using OpenTK library to embed an Opengl control onto C++ windows form. However, OpenTK doesn't support GLUT, so I cannot easily create primitive geometry such as cube, sphere, tetrahedron, etc. I actually plan to use all of the platonic solids, so recreating the whole dodecahedron triangles would waste me a lot of time. Is there a way to use GLUT in OpenTK? or is there an alternative functions to drawing platonic solids or primitive geometries in OpenTK?
Thanks
OpenTK can only be used in context with C#. The problem is that there is no Glut library for C# because everybody uses C++ instead. Actually it is not OpenTK that does not support Glut, it's C# that doesn't.
Of course one could use C# with OpenTK and reference Tao.FreeGlut.dll which is a portation of the Glut library onto C#. That way you could use FreeGlut and would still have the advantage of OpenTK (which superseded Tao). OpenTK does not bring a FreeGlut portation itself like Tao does.
If you use C++, just get the regular freeglut.dll as discribed in this post: glut and Visual Studio 2010

CGL vs AGL vs OpenGL vs NSOpenGL vs CoreAnimation(CALayer)

I am trying to understand few things on Mac related to OpenGL framework integration in the form of layers. Well basically when I want to understand 3D technologies present in OS X and which layer is OpenGL's actual implentation layer.
From reading apple docs, below is what I have understood so far:
1.NSOpenGLContext object wraps a low-level, platform-specific Core OpenGL (CGL) context.
= This makes it clear that NSOpenGL makes use of CGL.
2.The AGL (Apple Graphics Library) API is part of the Apple implementation of OpenGL in Mac OS X.
= So, does AGL and CGL are related in any way?
3.CGL (Core OpenGL) is the lowest-level programming interface for the Apple implementation of OpenGL.
= Does it mean Standard OpenGL API's are just wrapper over CGL?
4.CoreAnimation seems to be combo of Core Graphics, Open-GL and Quick-time. But I am not sure what it uses underneath it, I mean actual implementation layer, is it again CGL?
Things are not completely clear to me. I am still reading though and I have asked somewhat related question in past but with incomplete knowledge.
I would really appreciate if someone can share his understanding on matter.
NSOpenGLContext, AGL and CGL are all APIs for setting up an OpenGL context you can draw into.
Use NSOpenGLContext unless you already know you have a reason not to.
Use AGL if you are writing a Carbon application or if you need compatibility with Mac OS 9 (As of 2012, that basically means: don't).
Both AGL and NSOpenGLContext are implemented on top of CGL. However, not all the necessary parts of CGL are actually public APIs. Last time I checked, the only public parts of the CGL API where the ones that allow you to create a fullscreen OpenGL context. If you want OpenGL in a window or you want the option of showing dialog boxes or some NSViews on top of your OpenGL, you probably can't use CGL.
CoreAnimation is a framework for (mostly UI) animations; you can use CoreAnimation without using OpenGL directly. I have never used it myself, but I assume it also allows you to create an OpenGL context for an animation layer. Use it if you already have other reasons to use CoreAnimation, or if you want to combine OpenGL graphics and Mac GUI widgets in creative ways.

DirectX 2D drawing with Vb.net

I'm using using System.Graphics for my latest project (A simple 2D application). Problem is, it gets a horrible FPS and I'm only drawing 8x8 tiles (usually 10-12 is enough to bring it down to 12FPS).
A friend of mine suggested that I use DirectX. He also suggested XNA but I opposed because I don't want my clients to have to install the XNA distributional. DirectX is common enough (to my knowledge) and I can just include the dll's if I need to.
So, my search began. I've been looking only for DirectX 2D tutorials for VB.net. I've had no solid success thus far. In truth, all I need to do is be able to draw bitmap x at position pos.
I've been using System.Graphics and a hacked up bitmap as my buffer thus far so I'll go for any improvement that I can get.
I'm using VB.net so I'll be ok if you give my one for C#, I'm pretty good at being able to read it (and I have a nice converter too). I would just prefer VB.net to save time.
Thanks! :)
This article in MSDN Magazine was in 2003 edition had a nice example of managed DirectX code in action:
http://msdn.microsoft.com/en-us/magazine/cc164112.aspx
Sadly enough, currently, there's no managed library of DirectX (a.k.a. DirectX .NET wrapper) in DX 10 and DX 11. Microsoft only provided managed library for DX 9.0a and DX 9.0b.
In Managed DirectX wikipedia, you'll see that it's being replaced by Microsoft XNA.
If you download current/latest DirectX SDK, you will have samples only in C++ and HLSL codes.
If you really need fancy UI and also nice animation and 3D drawing based on DirectX, you can go use WPF, especially WPF in .NET 3.0 SP2 (or simply download and install .NET 3.5 SP1). WPF is build on top of DirectX 9.0c stack, without worrying to know large libraries of DirectX 9 API. You'll also get 3D primitives support too.
More on WPF, visit this:
http://msdn.microsoft.com/en-us/library/ms754130.aspx