当顶点在for循环中时glDrawElements不绘制

时间:2019-03-01 23:18:21

标签: c++ opengl

我试图使用顶点数组创建一个圆,将点填充在for循环中,但是什么也没有显示,相反,如果我将值手动放入数组中,一切正常不知道什么是错的。

#include <cstdlib>
#include <cmath>
#include <iostream>

#include <GL/glew.h>
#include <GL/freeglut.h> 

#define PI 3.14159265358979324

static float R = 40.0; // Radius of circle.
static float X = 50.0; // X-coordinate of center of circle.
static float Y = 50.0; // Y-coordinate of center of circle.
static int numVertices = 5; // Number of vertices on circle.

static float vertices[15] =
{

};

static unsigned int stripIndices[] = { 0, 1, 2, 3, 4};

// Drawing routine.
void drawScene(void)
{
    float t = 0; // Angle parameter.
    int i;


    int k = 1;
    for (i = 0; i < numVertices; i++)
    {
        vertices[k] = X + R * cos(t);
        k++;
        vertices[k] = Y + R * sin(t);
        k++;
        vertices[k] = 0.0;

        k++;
        t += 2 * PI / numVertices;
    }



    glClear(GL_COLOR_BUFFER_BIT);

    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    glColor3f(1.0, 0.0, 0.0);
    glDrawElements(GL_LINE_LOOP, 5, GL_UNSIGNED_INT, stripIndices);

    glFlush();
}

1 个答案:

答案 0 :(得分:0)

哦,刚注意到您执行'k = 1'。应该是“ k = 0”。