Comments (3)
What is the OpenTkInit()
function and where in the code is it?
What version of OpenTK are you using?
Are you running code on different threads?
from learnopentk.
First of all, I'm using OpenTK in the Avalonia project. Avalonia's version is 0.10.14 and OpenTK's version is 4.7.7
All my code is single thread for now.
I took this code as reference OpenTKAvalonia.
Here is the "original" OpentTkInit method:
protected override void OpenTkInit()
{
//Compile shaders
_shader = new("Shaders/shader.vert", "Shaders/shader.frag");
//Load textures
_brickTexture = new();
_brickTexture.Use();
_brickTexture.LoadFromFile("Textures/wall.jpg");
//Set textures in shaders
_shader.Use();
_shader.SetInt("texture0", 2);
//Create vertex and buffer objects
_vertexArrayObject = GL.GenVertexArray();
_vertexBufferObject = GL.GenBuffer();
//Set bg colour to a dark forest green
GL.ClearColor(0.2f, 0.3f, 0.3f, 1.0f);
//Bind to the VAO
GL.BindVertexArray(_vertexArrayObject);
//Set up the buffer for the triangle
GL.BindBuffer(BufferTarget.ArrayBuffer, _vertexBufferObject);
//Copy triangle vertices to the buffer
GL.BufferData(BufferTarget.ArrayBuffer, _vertices.Length * sizeof(float), _vertices, BufferUsageHint.StaticDraw);
//Configure structure of the vertices
// (position parameter in vertex shader, 3 points, data is stored as floats, non-normalized, 5 floats/point, first point at offset 0 in data array)
GL.VertexAttribPointer(_shader.GetAttribLocation("aPosition"), 3, VertexAttribPointerType.Float, false, 5 * sizeof(float), 0);
GL.EnableVertexAttribArray(_shader.GetAttribLocation("aPosition"));
//Configure texture coordinate structure
var texCoordLocation = _shader.GetAttribLocation("aTexCoord");
GL.VertexAttribPointer(texCoordLocation, 2, VertexAttribPointerType.Float, false, 5 * sizeof(float), 3 * sizeof(float));
GL.EnableVertexAttribArray(texCoordLocation);
//Set up the EBO
_elementBufferObject = GL.GenBuffer();
//Set up its buffer
GL.BindBuffer(BufferTarget.ElementArrayBuffer, _elementBufferObject);
//Copy data to the buffer
GL.BufferData(BufferTarget.ElementArrayBuffer, _indices.Length * sizeof(uint), _indices, BufferUsageHint.StaticDraw);
}
From the base class BaseTkOpenGlControl
inherited from the Avalonia.OpenGL.Controls.OpenGlControlBase
:
protected sealed override void OnOpenGlInit(GlInterface gl, int fb)
{
//Initialize the OpenTK<->Avalonia Bridge
_avaloniaTkContext = new(gl);
GL.LoadBindings(_avaloniaTkContext);
//Invoke the subclass' init function
OpenTkInit();
}
//Simply call the subclass' teardown function
protected sealed override void OnOpenGlDeinit(GlInterface gl, int fb)
{
OpenTkTeardown();
//Workaround an avalonia issue where the depth buffer ID is not cleared
//which causes depth problems (see issue #1 on this repo)
_depthBufferField.SetValue(this, 0);
}
That works ok. My issue is about moving all job with buffers to the other method whith runs in the app's runtime. Absolutely same code but in the other place.
from learnopentk.
You need to make sure that you have an opengl context current on the thread. Is it possible that the "runtime" function doesn't have a context current?
from learnopentk.
Related Issues (20)
- The name 'CursorGrabbed' does not exist in the current context HOT 2
- Chapter2/6-MultipleLights sample is broken HOT 14
- .NET PixelFormat to ES30 HOT 4
- OSX: Chapter 1/1 not working on OSX HOT 7
- Console and Winform HOT 1
- wrong accessibility level for Shader.Use() HOT 2
- Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. HOT 3
- Confusing openTK implement openGL version 2,3,4 HOT 3
- Why OpenTK does not support Matrix4.CreatePerspective( ) method ?. What are the differences between Matrix4.CreatePerspective( ) vs Matrix4.CreatePerspectiveFieldOfView( ) HOT 3
- System.Drawing.Common is not supported on non-Windows platforms. HOT 3
- No link in readme to actual tutorial HOT 2
- Where can I find examples for ES20? HOT 2
- Open TK HOT 2
- Tutorial: Questionable Shader class disposal advice/code HOT 3
- Hello Triangle shader class? HOT 2
- Resizing window on MacOS doesn't take care of the scale factor*2 HOT 1
- FYI: Converting LearnOpenGL HOT 2
- OnResize() is not using FramebufferSize property HOT 1
- GLSL typically uses column-major,but the demo shader of "7-Transformations" use pre-multiplication HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from learnopentk.