在OpenGL中绘制线的问题
Issues drawing a line in OpenGL
我已经有了一个可以绘制纹理对象的程序。我想绘制调试线,所以我尝试复制我用于精灵绘制线的相同绘制过程。我做了一个新的片段和顶点着色器,因为线条不会被纹理化,有一个不同的调试着色器可能是有用的。
如果我试图画一条线,但这条线没有画出来,我的系统继续工作。我试图为我的精灵编写类似于工作代码的代码,但显然我遗漏了一些东西或犯了一个错误。
顶点着色器:
#version 330 core
layout (location = 0) in vec2 position;
uniform mat4 uniformView;
uniform mat4 uniformProjection;
void main()
{
gl_Position = uniformProjection * uniformView * vec4(position, 0.0f, 1.0f);
}
片段着色器:
#version 330 core
out vec4 color;
uniform vec4 uniformColor;
void main()
{
color = uniformColor;
}
绘图代码:
void debugDrawLine(glm::vec3 startPoint, glm::vec3 endPoint, glm::vec3 color, Shader debugShader)
{
GLint transformLocation, colorLocation;
GLfloat lineCoordinates[] = { startPoint.x, startPoint.y,
endPoint.x, endPoint.y};
GLuint vertexArray, vertexBuffer;
glLineWidth(5.0f);
glGenVertexArrays(1, &vertexArray);
glGenBuffers(1, &vertexBuffer);
glBindVertexArray(vertexArray);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
debugShader.Use();
//Copies the Vertex data into the buffer
glBufferData(GL_ARRAY_BUFFER, sizeof(lineCoordinates), lineCoordinates, GL_STATIC_DRAW);
glVertexAttribPointer(
0, // attribute 0. No particular reason for 0, but must match the layout in the shader.
2, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
2*sizeof(GL_FLOAT), // stride
(GLvoid*)0 // array buffer offset
);
//Sends the sprite's color information in the the shader
colorLocation = glGetUniformLocation(debugShader.Program, "uniformColor");
glUniform4f(colorLocation, 1.0f, color.x, color.y, color.z);
//Activates Vertex Position Information
glEnableVertexAttribArray(0);
// Draw the line
glDrawArrays(GL_LINES, 0, 2);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
}
核心配置文件不允许行宽大于1。如果将大小设置为1
相关文章:
- 警告处理为错误这里有什么问题
- 最小硬币更换问题(自上而下方法)
- 在顶点着色器中使用 OpenGl 的未声明标识符,我在顶点着色器中绘制三角形时遇到问题
- 绘制文本问题
- 我正在尝试创建一个 C++ 贪吃蛇游戏,但我似乎无法绘制第二个高度边框,我该如何解决这个问题?
- 在 Qt C++ 中在自定义项委托上绘制文本时的性能问题
- 绘制的 OpenGL 点消失,绘制调用和交换缓冲区问题
- 绘制非常大的 2D 图形时出现问题
- 对于循环重复绘制问题
- 绘制多边形网格时出现 Opengl 性能问题
- TMX问题,在正确位置绘制瓷砖(c++)
- 使用纹理,法线和索引列表从VBO绘制OpenGL对象的问题
- 简单的地图绘制问题
- 使用SpriteFont类绘制文本时出现问题
- 在 SDL 中,当我在屏幕上绘制菜单时,它会使游戏变慢并且无法正常工作,我该如何解决这个问题?
- 为什么我的非所有者绘制的列表框在添加字符串后会出现绘图问题
- opengl =中缓冲区数据的问题仅在我缓冲比需要更多的字节时绘制
- 在OpenGL中绘制线的问题
- Direct3d绘制2d精灵.扩展问题
- Q项目绘制问题