opengl纯动态管线备忘

in 编程
关注公众号【好便宜】( ID:haopianyi222 ),领红包啦~
阿里云,国内最大的云服务商,注册就送数千元优惠券:https://t.cn/AiQe5A0g
腾讯云,良心云,价格优惠: https://t.cn/AieHwwKl
搬瓦工,CN2 GIA 优质线路,搭梯子、海外建站推荐: https://t.cn/AieHwfX9
static const float p_vertex[12] = {-0.5,0.5,0.0, -0.5,-0.5,0.0, 0.5,-0.5,0.0, 0.5,0.5,0.0};
static const short p_index[6] = {0,1,2, 0,2,3};
static ssShader*    g_shader = 0;
static GLuint        g_vao = 9999;
static GLuint        g_vbo[3];

{//glDrawArrays
    //vao
    glGenVertexArrays(1, &g_vao);
    glBindVertexArray(g_vao);
    //vbo
    glGenBuffers(1, &g_vbo[0]);  
    glBindBuffer(GL_ARRAY_BUFFER, g_vbo[0]);
    glBufferData(GL_ARRAY_BUFFER, sizeof(float)*12, p_vertex, GL_STATIC_DRAW);
    //绑定vbo到vao
    glEnableVertexAttribArray(0);
    //glBindBuffer(GL_ARRAY_BUFFER, g_vbo[0]);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);

    glBindVertexArray(0);  
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    glBindVertexArray(g_vao);
    glDrawArrays(GL_TRIANGLES, 0, 3);
    glBindVertexArray(0);
}

{//glDrawElements
    //vao
    glGenVertexArrays(1, &g_vao);
    glBindVertexArray(g_vao);
    //vbo
    glGenBuffers(1, &g_vbo[0]); 
    glBindBuffer(GL_ARRAY_BUFFER, g_vbo[0]);
    glBufferData(GL_ARRAY_BUFFER, sizeof(float)*12, p_vertex, GL_STATIC_DRAW);
    glGenBuffers(1, &g_vbo[1]);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_vbo[1]);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(short)*6, p_index, GL_STATIC_DRAW);
    //绑定vbo到vao
    glEnableVertexAttribArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, g_vbo[0]);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);

    glBindVertexArray(0); 
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

    glBindVertexArray(g_vao);
    //glDrawArrays(GL_TRIANGLES, 0, 3);
    glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
    glBindVertexArray(0);
}

必须先调用glBindVertexArray(0)再调用glBindBuffer(GL_ARRAY_BUFFER, 0)

 

关注公众号【好便宜】( ID:haopianyi222 ),领红包啦~
阿里云,国内最大的云服务商,注册就送数千元优惠券:https://t.cn/AiQe5A0g
腾讯云,良心云,价格优惠: https://t.cn/AieHwwKl
搬瓦工,CN2 GIA 优质线路,搭梯子、海外建站推荐: https://t.cn/AieHwfX9
扫一扫关注公众号添加购物返利助手,领红包
Comments are closed.

推荐使用阿里云服务器

超多优惠券

服务器最低一折,一年不到100!

朕已阅去看看