我想绘制一个球体,我知道如何使用glBegin()和glEnd()之类的调用在OpenGL中完成它.
但ES中没有任何内容.
建议/教程链接?
我想渲染围绕一组点的动态变化半径的实心圆,其2D坐标存储在VBO中.到目前为止,我使用的是GL_POINT_SMOOTH,但现在已转移到OpenGL 4.0,此选项不再可用.我在这里看到了类似的问题,但这并不适合我的需要,因为该示例中圆圈的中心在片段着色器中是硬编码的.我该怎么做?
目前,我的顶点着色器看起来像这样:
#version 400
layout(location=0) in vec2 in_Position;
layout(location=1) in vec4 in_Color;
out vec4 ex_Color;
uniform vec4 bounds;
void main(void){
float x = -1+2/(bounds.y-bounds.x)*(in_Position.x-bounds.x);
float y = -1+2/(bounds.w-bounds.z)*(in_Position.y-bounds.z);
gl_Position = vec4(x,y,0,1);
ex_Color = in_Color;
}
Run Code Online (Sandbox Code Playgroud)
我的片段着色器看起来像这样:
#version 400
in vec4 ex_Color;
out vec4 out_Color;
void main(void){
out_Color = ex_Color;
}
Run Code Online (Sandbox Code Playgroud)
使用这些着色器,我得到了平方点.
我知道在2.0-openGL中我们可以像这样绘制一条线.
glBegin(GL_LINES);
glVertex3f(20.0f,150.0f,0.0f);
glVertex3f(220.0f,150.0f,0.0f);
glVertex3f(200.0f,160.0f,0.0f);
glVertex3f(200.0f,160.0f,0.0f);
glEnd();
Run Code Online (Sandbox Code Playgroud)
但如何在现代openGL(3.0+)中做类似的事情
我已经阅读了使用现代OpenGL绘制圆形点,但答案不是关于某一点,因为我想绘制具有一定坐标的点的多边形,这不是很有用.
我使用这个代码,但它除了蓝色背景外什么都没显示.我错过了什么?
GLuint VertexArrayID;
glGenVertexArrays(1, &VertexArrayID);
glBindVertexArray(VertexArrayID);
static const GLfloat g_vertex_buffer_data[] = {
20.0f, 150.0f, 0.0f, 1.0f,
220.0f, 150.0f, 0.0f, 1.0f,
200.0f, 160.0f, 0.0f, 1.0f
};
GLuint vertexbuffer;
glGenBuffers(1, &vertexbuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);
do{
// Clear the screen
glClear( GL_COLOR_BUFFER_BIT );
// 1rst attribute buffer : vertices
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glVertexAttribPointer(
0, // attribute 0. No particular reason for 0, but must match the layout in the …Run Code Online (Sandbox Code Playgroud)