OpenGL正在绘制UV贴图而不是网格
OpenGL is drawing the UV map instead of the mesh
我正在关注一个关于OpenGL开发的YouTube教程系列。他已经在github上上传了代码。但是,下载的代码似乎绘制了UV贴图而不是网格本身。
我试图隔离问题,我认为问题出在网格.cpp。我可能是错的。也许问题出在 glDrawElementsBaseVertex 行中,因为我们没有指定指向索引数组的指针。
void Mesh::Draw()
{
glBindVertexArray(m_vertexArrayObject);
glDrawElementsBaseVertex(GL_TRIANGLES, m_numIndices, GL_UNSIGNED_INT, 0, 0);
glBindVertexArray(0);
}
我尝试交换位置和纹理坐标,但这似乎不起作用。
glBindBuffer(GL_ARRAY_BUFFER, m_vertexArrayBuffers[POSITION_VB]);
glBufferData(GL_ARRAY_BUFFER, sizeof(model.positions[0]) * model.positions.size(), &model.positions[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_vertexArrayBuffers[TEXCOORD_VB]);
glBufferData(GL_ARRAY_BUFFER, sizeof(model.texCoords[0]) * model.texCoords.size(), &model.texCoords[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, 0);
由于我是OpenGL的新手,因此无法解决此问题。我已经问过YouTuber,但我还没有得到答复。
我的显卡可能与OpenGL 120有一些兼容性问题,所以我将其更改为330并进行了一些更改,一切开始正常工作。以下是我所做的更改。
basicShader.vs
#version 330
layout(location = 0) in vec3 position;
layout(location = 1) in vec2 texCoord;
layout(location = 2) in vec3 normal;
out vec2 texCoord0;
out vec3 normal0;
uniform mat4 MVP;
uniform mat4 Normal;
void main()
{
gl_Position = MVP * vec4(position, 1.0);
texCoord0 = texCoord;
normal0 = (Normal * vec4(normal, 0.0)).xyz;
}
basicShader.fs
#version 330
out vec4 color;
in vec2 texCoord0;
in vec3 normal0;
uniform sampler2D sampler;
uniform vec3 lightDirection;
void main()
{
color = texture(sampler, texCoord0) *
clamp(dot(-lightDirection, normal0), 0.0, 1.0);
}
相关文章:
- QuadTree只在窗口的右上角绘制
- 绘制旋转的三角形
- 如何使用 sdl2 快速绘制像素网格?
- 使用 OpenGL 绘制 8 x 15 矩形网格C++ - 崩溃
- QT3D-如何不绘制网格
- 如何在C++中创建一个网格,这将允许我将每个索引设置为一个向量,以便以后操作该向量,然后绘制它
- c++OpenGL发布用存储在对象中的vbo和vao绘制网格
- FreeGlut网格图未完全以特定值绘制
- 绘制网格最有效的方法是什么
- 想要在从搅拌机导入的实体3D对象上绘制线框网格
- 绘制多边形网格时出现 Opengl 性能问题
- 如何在opengl中绘制屏幕一小部分大小的正方形网格
- OpenGL优化网格绘制(VAO?无索引?)
- C ++ OpenGL 只绘制 1 个点而不是网格
- openGL在将参数传递给要绘制的函数时不绘制网格
- OpenGL正在绘制UV贴图而不是网格
- 在网格中绘制具有捕捉功能的线条
- 在vtkXYPlotActor中绘制网格线
- 使用glDrawElements绘制3D网格时的奇怪行为
- 绘制多个网格到不同的位置(DirectX 12)