wasabia / flutter_gl

cross-platform call OpenGL API by Dart through dart:ffi. Provides OpenGL with Texture Widget on Flutter.
245 stars 60 forks source link

Example doesn't work correctly on Windows #48

Open organic-nailer opened 1 year ago

organic-nailer commented 1 year ago

Hello. Thank you for creating such an amazing package!

I tried to run example app (flutter_gl/example), but when I run it on Windows, the triangle doesn't show up. When I run it on the Web under the same condition, it displays correctly. Could you see what's wrong?

beelabcloud commented 1 year ago

The example should work on Intel integratied graphic rather AMD or Nvidia adapter. The vertex shader should be like: """#version 300 es precision mediump float; in vec4 a_position; in vec2 a_texCoord; out highp vec2 vTexCoord; void main() { gl_Position = a_position; vTexCoord = a_texCoord; } """;

beelabcloud commented 1 year ago

for AMD case, "vec4 a_position" is the key, vec2/vec3 just not working, I don't know why.

organic-nailer commented 1 year ago

I found a weak solution in my environment (Windows/AMD).

https://github.com/organic-nailer/flutter_gl_sample_windows/blob/master/lib/main.dart

for AMD case, "vec4 a_position" is the key, vec2/vec3 just not working, I don't know why.

The above solution was not effective in my environment. I found that calling glVertexAttribPointer twice results in the correct display instead. I don't know why this code works correctly.

gl.bindVertexArray(_vao);
{
  gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
  gl.enableVertexAttribArray(positionLocation);
  // call twice
  gl.vertexAttribPointer(positionLocation, 4, gl.FLOAT, false, 4 * Float32List.bytesPerElement, 0);
  gl.vertexAttribPointer(positionLocation, 4, gl.FLOAT, false, 4 * Float32List.bytesPerElement, 0);
}
gl.bindVertexArray(0);