- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 OpenGL 3.3 和 EGL 1.4。我用来构建和运行我的代码 (C) 的笔记本电脑使用英特尔的 HD 3000 集成 GPU 并运行 linux。因此,我使用 Mesa 3D 库。在我的程序中,我在 X11 窗口中创建并绑定(bind)了一个 OpenGL 3.3 核心配置文件兼容上下文,由稍后返回的 glGetString(GL_VERSION)
字符串“3.3 (Core Profile) Mesa 13.0.6”确认.
接下来,我使用 EGL 加载 OpenGL 规范的各种函数(我选择不使用 GLEW 等库)。完成此操作后,我开始设置 OpenGL 状态以渲染普通三角形。我初始化了一个 float 组,它们构成了三角形的 3 个硬编码顶点。然后,我初始化并绑定(bind)一个顶点数组对象,接着初始化并绑定(bind)一个顶点缓冲区对象。最后,我将我的顶点数组传递给 glBufferData,以将顶点数据与顶点缓冲区对象链接起来。
unsigned int vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
unsigned int vbo;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
然后,我初始化了一个基本的顶点和片段着色器。都编译成功,我的着色器程序链接成功,验证成功。
#version 330 core
layout (location = 0) in vec3 p;
void main(){
gl_Position = vec4(p, 0.0);
}
#version 330 core
out vec4 color;
void main(){
color = vec4(0.0, 0.0, 0.0, 1.0);
}
然后我继续告诉 GL 如何解释我的顶点数据;
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void *)0);
glEnableVertexAttribArray(0);
最后,我进入程序的主循环,负责绘制和交换帧缓冲区,其中 bufferloop 是 struct timespec bufferloop = (struct timespec){0, 250000};
while(app.running){
glClearColor(1.0, 1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES, 0, 3);
eglSwapBuffers(egldisplay, eglsurface);
nanosleep(&bufferloop, (void *)0);
}
我得到的只是一个白屏;我的三角形无处可寻。我终生无法确定问题出在哪里。我已将 printf("%d\n", glGetError());
粘贴到我的所有代码中,但未出现任何错误。glDrawArrays(GL_TRIANGLES, 0, 3);
毫无征兆地失败了。
最佳答案
在你的顶点着色器中,w
组件应该是 1 而不是 0。OpenGL 红皮书 here 中有很好的描述。描述了如何使用 w
。简而言之:
OpenGL commands usually deal with two- and three-dimensional vertices, but in fact all are treated internally as three-dimensional homogeneous vertices comprising four coordinates. Every column vector (x, y, z, w)T represents a homogeneous vertex if at least one of its elements is nonzero.
As long as w is nonzero, the homogeneous vertex (x, y, z, w)T corresponds to the three-dimensional point (x/w, y/w, z/w)T. If w = 0.0, it corresponds to no euclidean point, but rather to some idealized "point at infinity." To understand this point at infinity, consider the point (1, 2, 0, 0), and note that the sequence of points (1, 2, 0, 1), (1, 2, 0, 0.01), and (1, 2.0, 0.0, 0.0001), corresponds to the euclidean points (1, 2), (100, 200), and (10000, 20000). This sequence represents points rapidly moving toward infinity along the line 2x = y. Thus, you can think of (1, 2, 0, 0) as the point at infinity in the direction of that line.
关于c - OpenGL 3.3 核心配置文件 - glDrawArrays 无声地失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45003134/
我正在处理一个个人 Java OpenGL (JOGL) 项目,我正在使用一些具有独立绘制函数和顶点的自定义对象。 public class Cube extends PhysicalObject {
我正在尝试渲染巨大的点云 (~150M),但 OpenGL 只渲染其中的一部分 (~52M)。渲染较小的数据集(glMapBufferRange,这可能会解决 4GB 的限制。 要考虑的另一件事是使用
我正在尝试渲染一个可以扩展到其他对象的四面体。 使用静态数组可以很好地绘制四面体。 但是当我将 OFF 文件读入动态数组时,什么也没有出现。编译时没有出现错误。 GLfloat *tetra_vert
我尝试使用 glDrawArray 和 GL_TRIANGLE_STRIP 渲染纹理网格,但绘制时存在伪影,但在屏幕上分布不均匀。 Screenshot of the problem. 这是我使用的代
伪代码: void draw() { Vertex* vertices = scene.GetVertexArray(); glEnableClientState(...);
我有一个未声明顶点属性的顶点着色器。它根据 UBO、gl_VertexId 和 gl_InstanceID 计算所有需要的值。 我know必须绑定(bind)非零 VAO 才能渲染。 那么,在当前 V
我正在关注一些初学者 OpenGL 教程,并且对这段代码有点困惑: glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject); //Bind GL_ARRAY
我正在尝试在 glDrawArray 上修改程序。如果我只使用glVertex3f一切都很好,如果我使用glDrawArrays`作为相同的顶点值,除了图形之外,我还会得到一些随机线。 与glDraw
我在 python3 中有这段代码,它不能在 Windows 机器上运行,但可以在 Linux 机器上运行。我绘制了一个绿色屏幕和一个红色三角形,但红色三角形仅在我退出时出现。 import pyga
我正在尝试遵循 [this][1] 简单教程,但在到达“glDrawArrays”时出现以下错误: openGLTest.exe 中 0x03D7598E (nvoglv32.dll) 处的未处理异常
我正在使用以下代码在某些指定坐标处绘制一条绿线 GLfloat colors[] = {0,1,0,1, 0,1,0,0.5}; CGPoint v[] = {{p1.x, p1.y},
我使用 vector 来存储顶点和法线数据 vector vertex; vector normal; 例如: normal.push_back(-1); normal.push_back(0); n
我正在尝试做一个简单的 Pong 游戏,但我遇到了一些问题。本质上,我有一个由四个点组成的数组,x 和 y 值表示一个硬编码的球,我需要让那个球正确显示。当我尝试使用 glDrawArray 时,我一
我最近发现 glDrawArrays 在每一帧上分配和释放大量内存。我怀疑它与 openGL 探查器报告的“Shaders compiled outside initialization”问题有关。这
当我尝试使用 glDrawArrays 绘制圆时,它显示四分之一 circle 由代码生成的 VBO 是正确的。顺便说一句,没有 0,0,0 这样的坐标。它似乎只绘制正顶点,但如果我将顶点乘以 -1
我在 openGL 的固定流水线上花了很多时间,最近开始学习可编程流水线。我认识我的画家,着色器类不是问题,因为它们使用固定功能管道的东西。我似乎无法让 glDrawArrays 为我的生活工作。 我
在循环遍历我想在 3D 引擎中渲染的所有对象时,尝试调用时出现错误 glDrawArrays(mesh->primitiveType, 0, mesh->vertexCount); 因为它试图从位置
好的,所以我仍在努力让它发挥作用。我的代码的重要部分是: def __init__(self, vertices, normals, triangles): self.bufferVertic
在通过 lwjgl 学习如何使用 OpenGL 3.2 时,我遵循了 here 上的教程.我一直在方法调用 glDrawArrays 上收到无效操作错误。如果我从教程中复制源代码,甚至会发生此错误。
我有一堆要绘制的多边形数据。我提取了那个绘图代码,现在它看起来像这样 for (int Index = 0; Index < Count; Index++) { glDrawArrays(GL
我是一名优秀的程序员,十分优秀!