加载的obj模型闪烁并崩溃应用程序

时间:2017-05-18 23:41:01

标签: c++ opengl

我正在尝试从obj文件加载模型并在OpenGL 2.0中显示它,但我有两个问题。

加载的模型有时会随机闪烁并使我的应用程序崩溃。

我不知道是什么导致异常,因为我甚至没有堆栈跟踪。 我只有“Frame not in module”和消息:

Exception thrown at 0x000000CE25E7FF68 in Clock.exe: 0xC0000005: Access violation reading location 0x000000CE26640000.

你知道出了什么问题吗?码?文件?

ObjLoader.h:

#pragma once

#include <vector>

using namespace std;

typedef struct _vertex {
    float x, y, z;
} Vertex;

typedef struct _face {
    unsigned int v, vn;
} Face;

struct ObjModel
{
    vector<Vertex> Vertices;
    vector<Vertex> Normals;
    vector<vector<Face>> Faces;
};

class ObjLoader
{
    public:
        ObjModel LoadObjModel(const char* filePath);
    private:
        void ProcessIndices(ObjModel &model);
        void ProcessLine(string &dataType, stringstream &ss, ObjModel &model);

        Vertex ObjLoader::GetVertex(stringstream &ss);
        vector<Face> ObjLoader::GetFaces(stringstream &ss);
};

ObjLoader.cpp:

#include "ObjLoader.h"
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>

using namespace std;

ObjModel ObjLoader::LoadObjModel(const char* filePath)
{
    ObjModel model;

    fstream in(filePath);
    string line;

    while (std::getline(in, line))
    {
        if (line.empty())
        {
            continue;
        }

        string dataType = line.substr(0, 2);

        line = line.substr(2, line.size() - 2);

        if (line[0] == ' ')
        {
            line = line.substr(1, line.size() - 1);
        }

        stringstream ss(line);

        ProcessLine(dataType, ss, model);
    }

    ProcessIndices(model);

    return model;
}

void ObjLoader::ProcessLine(string &dataType, stringstream &ss, ObjModel &model)
{
    if (dataType == "v ")
    {
        model.Vertices.push_back(GetVertex(ss));
    }
    else if (dataType == "vn")
    {
        model.Normals.push_back(GetVertex(ss));
    }
    else if (dataType == "f ")
    {
        vector<Face> faces = GetFaces(ss);

        model.Faces.push_back(faces);
    }
}

Vertex ObjLoader::GetVertex(stringstream &ss)
{
    Vertex vertex;

    ss >> vertex.x >> vertex.y >> vertex.z;

    return vertex;
}

vector<Face> ObjLoader::GetFaces(stringstream &ss)
{
    vector<Face> faces;

    string s;

    while (getline(ss, s, ' '))
    {
        Face face;

        int a, b;

        sscanf(s.c_str(), "%d//%d", &a, &b);

        face.v = a;
        face.vn = b;

        faces.push_back(face);
    }

    return faces;
}

void ObjLoader::ProcessIndices(ObjModel &model)
{
    ObjModel temp;

    temp.Vertices = vector<Vertex>();
    temp.Normals = vector<Vertex>();

    for (int i = 0; i < model.Faces.size(); i++)
    {
        for (int j = 0; j < model.Faces[i].size(); j++)
        {
            unsigned int vertexIndex = model.Faces[i][j].v - 1;
            unsigned int normalIndex = model.Faces[i][j].vn - 1;

            Vertex vertex = model.Vertices[vertexIndex];
            Vertex normal = model.Normals[normalIndex];

            temp.Vertices.push_back(vertex);
            temp.Normals.push_back(vertex);
        }
    }

    model.Vertices = temp.Vertices;
    model.Normals = temp.Normals;
}

显示模型:

float *vertices, *normals;

vertices = &model.Vertices[0].x;
normals = &model.Normals[0].x;

glEnable(GL_NORMALIZE);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);

glVertexPointer(3, GL_FLOAT, 0, vertices);
glNormalPointer(GL_FLOAT, sizeof(float) * 4,normals);
glDrawArrays(GL_TRIANGLES, 0, model.Vertices.size());

glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);

Obj文件:

v -0.048773 -0.250000 -1.004804
v -0.048773 0.250000 -1.004804
v 0.243863 0.250000 -0.975982
v 0.243863 -0.250000 -0.975982
v 0.784410 -0.250000 -0.156029
v 1.004804 -0.250000 -0.048773
v 0.975982 -0.250000 0.243863
v 0.738899 -0.250000 0.306062
v 0.664991 -0.250000 0.444333
v 0.744991 -0.250000 0.676016
v 0.517686 -0.250000 0.862560
v 0.306062 -0.250000 0.738899
v 0.156029 -0.250000 0.784410
v 0.048772 -0.250000 1.004804
v -0.243863 -0.250000 0.975981
v -0.306062 -0.250000 0.738898
v -0.444333 -0.250000 0.664991
v -0.676017 -0.250000 0.744991
v -0.862561 -0.250000 0.517685
v -0.738899 -0.250000 0.306061
v -0.784411 -0.250000 0.156028
v -0.293088 -0.250000 -0.006913
v -0.287323 -0.250000 0.051614
v -0.270251 -0.250000 0.107892
v -0.242528 -0.250000 0.159758
v -0.205220 -0.250000 0.205219
v -0.159759 -0.250000 0.242528
v -0.107893 -0.250000 0.270251
v -0.051615 -0.250000 0.287323
v 0.006912 -0.250000 0.293088
v 0.065440 -0.250000 0.287323
v 0.121718 -0.250000 0.270251
v 0.173584 -0.250000 0.242528
v 0.219045 -0.250000 0.205220
v 0.256353 -0.250000 0.159759
v 0.284076 -0.250000 0.107892
v 0.301148 -0.250000 0.051615
v 0.306913 -0.250000 -0.006913
v 0.306062 -0.250000 -0.738899
v 0.444333 -0.250000 -0.664991
v 0.676016 -0.250000 -0.744991
v 0.862560 -0.250000 -0.517686
v 0.738899 -0.250000 -0.306062
v 0.301148 -0.250000 -0.065440
v 0.284076 -0.250000 -0.121718
v 0.256353 -0.250000 -0.173584
v 0.219045 -0.250000 -0.219045
v 0.173584 -0.250000 -0.256353
v 0.121718 -0.250000 -0.284076
v 0.065440 -0.250000 -0.301148
v 0.006913 -0.250000 -0.306913
v -0.051614 -0.250000 -0.301148
v -0.107892 -0.250000 -0.284077
v -0.159758 -0.250000 -0.256354
v -0.205219 -0.250000 -0.219045
v -0.242528 -0.250000 -0.173584
v -0.270251 -0.250000 -0.121718
v -0.287323 -0.250000 -0.065440
v -1.004804 -0.250000 0.048772
v -0.975981 -0.250000 -0.243864
v -0.738898 -0.250000 -0.306063
v -0.664991 -0.250000 -0.444334
v -0.744990 -0.250000 -0.676017
v -0.517685 -0.250000 -0.862561
v -0.306061 -0.250000 -0.738899
v -0.156028 -0.250000 -0.784411
v -0.156028 0.250000 -0.784411
v -0.306061 0.250000 -0.738899
v -0.517685 0.250000 -0.862561
v -0.744990 0.250000 -0.676017
v -0.664991 0.250000 -0.444334
v -0.738898 0.250000 -0.306063
v -0.975981 0.250000 -0.243864
v -1.004804 0.250000 0.048772
v -0.784411 0.250000 0.156028
v -0.738899 0.250000 0.306061
v -0.862561 0.250000 0.517685
v -0.676017 0.250000 0.744991
v -0.444333 0.250000 0.664991
v -0.306062 0.250000 0.738898
v -0.243863 0.250000 0.975981
v 0.048772 0.250000 1.004804
v 0.156029 0.250000 0.784410
v 0.006912 0.250000 0.293088
v -0.051615 0.250000 0.287323
v -0.107893 0.250000 0.270251
v -0.159759 0.250000 0.242528
v -0.205220 0.250000 0.205219
v -0.242528 0.250000 0.159758
v -0.270251 0.250000 0.107892
v -0.287323 0.250000 0.051614
v -0.293088 0.250000 -0.006913
v -0.287323 0.250000 -0.065440
v -0.270251 0.250000 -0.121718
v -0.242528 0.250000 -0.173584
v -0.205219 0.250000 -0.219045
v -0.159758 0.250000 -0.256354
v -0.107892 0.250000 -0.284077
v -0.051614 0.250000 -0.301148
v 0.006913 0.250000 -0.306913
v 0.306062 0.250000 -0.738899
v 0.065440 0.250000 -0.301148
v 0.121718 0.250000 -0.284076
v 0.173584 0.250000 -0.256353
v 0.219045 0.250000 -0.219045
v 0.256353 0.250000 -0.173584
v 0.284076 0.250000 -0.121718
v 0.301148 0.250000 -0.065440
v 0.306913 0.250000 -0.006913
v 0.301148 0.250000 0.051615
v 0.284076 0.250000 0.107892
v 0.256353 0.250000 0.159759
v 0.219045 0.250000 0.205220
v 0.173584 0.250000 0.242528
v 0.121718 0.250000 0.270251
v 0.065440 0.250000 0.287323
v 0.306062 0.250000 0.738899
v 0.517686 0.250000 0.862560
v 0.744991 0.250000 0.676016
v 0.664991 0.250000 0.444333
v 0.738899 0.250000 0.306062
v 0.975982 0.250000 0.243863
v 1.004804 0.250000 -0.048773
v 0.784410 0.250000 -0.156029
v 0.738899 0.250000 -0.306062
v 0.862560 0.250000 -0.517686
v 0.676016 0.250000 -0.744991
v 0.444333 0.250000 -0.664991
vn 0.0980 0.0000 -0.9952
vn 0.0000 -1.0000 -0.0000
vn -0.8992 0.0000 -0.4376
vn 0.0000 1.0000 0.0000
vn 0.9673 0.0000 -0.2538
vn 0.4714 0.0000 -0.8819
vn -0.3264 0.0000 -0.9452
vn 0.7730 0.0000 -0.6344
vn 0.8634 0.0000 0.5045
vn 0.9569 0.0000 -0.2903
vn 0.4376 0.0000 -0.8992
vn 0.9952 0.0000 0.0980
vn 0.2538 0.0000 0.9673
vn 0.8819 0.0000 0.4714
vn 0.9452 0.0000 -0.3264
vn 0.6344 0.0000 0.7730
vn -0.5045 0.0000 0.8634
vn 0.2903 0.0000 0.9569
vn 0.8992 0.0000 0.4376
vn -0.0980 0.0000 0.9952
vn -0.9673 0.0000 0.2538
vn -0.4714 0.0000 0.8819
vn 0.3264 0.0000 0.9452
vn -0.7730 0.0000 0.6344
vn -0.8634 0.0000 -0.5045
vn -0.9569 0.0000 0.2903
vn -0.4376 0.0000 0.8992
vn -0.9952 0.0000 -0.0980
vn -0.2538 0.0000 -0.9673
vn -0.8819 0.0000 -0.4714
vn -0.9452 0.0000 0.3264
vn -0.6344 0.0000 -0.7730
vn 0.5045 0.0000 -0.8634
vn -0.2903 0.0000 -0.9569
vn 0.0980 0.0000 0.9952
vn -0.2903 0.0000 0.9569
vn 0.4714 0.0000 0.8819
vn -0.6344 0.0000 0.7730
vn 0.7730 0.0000 0.6344
vn -0.8819 0.0000 0.4714
vn 0.9569 0.0000 0.2903
vn -0.9952 0.0000 0.0980
vn 0.9952 0.0000 -0.0980
vn -0.9569 0.0000 -0.2903
vn 0.8819 0.0000 -0.4714
vn -0.7730 0.0000 -0.6344
vn 0.6344 0.0000 -0.7730
vn -0.4714 0.0000 -0.8819
vn 0.2903 0.0000 -0.9569
vn -0.0980 0.0000 -0.9952
s off
f 2//1 4//1 1//1
f 16//2 28//2 29//2
f 51//2 52//2 66//2
f 67//3 1//3 66//3
f 79//4 87//4 88//4
f 111//4 112//4 121//4
f 3//5 39//5 4//5
f 101//6 40//6 39//6
f 128//7 41//7 40//7
f 127//8 42//8 41//8
f 126//9 43//9 42//9
f 125//10 5//10 43//10
f 124//11 6//11 5//11
f 123//12 7//12 6//12
f 122//13 8//13 7//13
f 121//14 9//14 8//14
f 120//15 10//15 9//15
f 119//16 11//16 10//16
f 118//17 12//17 11//17
f 117//18 13//18 12//18
f 83//19 14//19 13//19
f 82//20 15//20 14//20
f 81//21 16//21 15//21
f 80//22 17//22 16//22
f 79//23 18//23 17//23
f 78//24 19//24 18//24
f 77//25 20//25 19//25
f 76//26 21//26 20//26
f 75//27 59//27 21//27
f 74//28 60//28 59//28
f 73//29 61//29 60//29
f 72//30 62//30 61//30
f 71//31 63//31 62//31
f 70//32 64//32 63//32
f 69//33 65//33 64//33
f 68//34 66//34 65//34
f 50//20 100//20 51//20
f 51//35 99//35 52//35
f 49//36 102//36 50//36
f 52//18 98//18 53//18
f 48//22 103//22 49//22
f 53//37 97//37 54//37
f 47//38 104//38 48//38
f 54//16 96//16 55//16
f 46//24 105//24 47//24
f 55//39 95//39 56//39
f 45//40 106//40 46//40
f 56//14 94//14 57//14
f 44//26 107//26 45//26
f 57//41 93//41 58//41
f 38//42 108//42 44//42
f 58//12 92//12 22//12
f 37//28 109//28 38//28
f 22//43 91//43 23//43
f 36//44 110//44 37//44
f 23//10 90//10 24//10
f 35//30 111//30 36//30
f 24//45 89//45 25//45
f 34//46 112//46 35//46
f 25//8 88//8 26//8
f 33//32 113//32 34//32
f 26//47 87//47 27//47
f 32//48 114//48 33//48
f 27//6 86//6 28//6
f 31//34 115//34 32//34
f 28//49 85//49 29//49
f 30//50 116//50 31//50
f 29//1 84//1 30//1
f 2//1 3//1 4//1
f 38//2 5//2 37//2
f 6//2 7//2 8//2
f 9//2 10//2 12//2
f 5//2 6//2 8//2
f 10//2 11//2 12//2
f 5//2 8//2 37//2
f 37//2 8//2 36//2
f 35//2 36//2 8//2
f 13//2 14//2 16//2
f 14//2 15//2 16//2
f 9//2 35//2 8//2
f 9//2 34//2 35//2
f 13//2 16//2 29//2
f 17//2 18//2 19//2
f 20//2 21//2 24//2
f 17//2 19//2 20//2
f 9//2 33//2 34//2
f 9//2 12//2 33//2
f 16//2 17//2 27//2
f 21//2 22//2 23//2
f 21//2 23//2 24//2
f 33//2 12//2 32//2
f 32//2 12//2 31//2
f 20//2 24//2 25//2
f 20//2 25//2 26//2
f 31//2 12//2 13//2
f 30//2 31//2 13//2
f 17//2 20//2 26//2
f 17//2 26//2 27//2
f 29//2 30//2 13//2
f 16//2 27//2 28//2
f 66//2 1//2 4//2
f 66//2 4//2 39//2
f 63//2 64//2 65//2
f 65//2 66//2 53//2
f 40//2 41//2 42//2
f 66//2 39//2 51//2
f 62//2 63//2 65//2
f 59//2 60//2 61//2
f 61//2 57//2 58//2
f 39//2 40//2 49//2
f 43//2 5//2 44//2
f 40//2 42//2 43//2
f 59//2 61//2 21//2
f 22//2 61//2 58//2
f 22//2 21//2 61//2
f 5//2 38//2 44//2
f 43//2 44//2 45//2
f 61//2 62//2 57//2
f 57//2 62//2 56//2
f 43//2 45//2 46//2
f 43//2 46//2 40//2
f 56//2 62//2 55//2
f 55//2 62//2 65//2
f 40//2 46//2 47//2
f 40//2 47//2 48//2
f 54//2 55//2 65//2
f 53//2 54//2 65//2
f 40//2 48//2 49//2
f 39//2 49//2 50//2
f 52//2 53//2 66//2
f 39//2 50//2 51//2
f 67//3 2//3 1//3
f 3//4 2//4 67//4
f 68//4 69//4 71//4
f 101//4 3//4 67//4
f 69//4 70//4 71//4
f 101//4 67//4 100//4
f 99//4 100//4 67//4
f 98//4 99//4 67//4
f 67//4 68//4 98//4
f 72//4 73//4 74//4
f 68//4 71//4 96//4
f 97//4 98//4 68//4
f 96//4 97//4 68//4
f 71//4 95//4 96//4
f 72//4 74//4 75//4
f 71//4 94//4 95//4
f 76//4 77//4 79//4
f 72//4 94//4 71//4
f 72//4 93//4 94//4
f 77//4 78//4 79//4
f 80//4 81//4 82//4
f 76//4 79//4 88//4
f 72//4 92//4 93//4
f 72//4 75//4 92//4
f 79//4 80//4 87//4
f 82//4 83//4 80//4
f 83//4 84//4 85//4
f 92//4 75//4 91//4
f 91//4 75//4 90//4
f 80//4 83//4 85//4
f 80//4 85//4 86//4
f 90//4 75//4 76//4
f 89//4 90//4 76//4
f 80//4 86//4 87//4
f 88//4 89//4 76//4
f 128//4 101//4 103//4
f 101//4 100//4 102//4
f 126//4 127//4 125//4
f 125//4 127//4 128//4
f 101//4 102//4 103//4
f 128//4 103//4 104//4
f 124//4 125//4 108//4
f 122//4 123//4 121//4
f 121//4 123//4 124//4
f 125//4 128//4 106//4
f 128//4 104//4 105//4
f 120//4 121//4 112//4
f 118//4 119//4 117//4
f 84//4 83//4 116//4
f 117//4 119//4 120//4
f 128//4 105//4 106//4
f 125//4 106//4 107//4
f 117//4 120//4 114//4
f 116//4 83//4 117//4
f 115//4 116//4 117//4
f 125//4 107//4 108//4
f 124//4 108//4 109//4
f 114//4 115//4 117//4
f 113//4 114//4 120//4
f 121//4 124//4 110//4
f 124//4 109//4 110//4
f 112//4 113//4 120//4
f 121//4 110//4 111//4
f 3//5 101//5 39//5
f 101//6 128//6 40//6
f 128//7 127//7 41//7
f 127//8 126//8 42//8
f 126//9 125//9 43//9
f 125//10 124//10 5//10
f 124//11 123//11 6//11
f 123//12 122//12 7//12
f 122//13 121//13 8//13
f 121//14 120//14 9//14
f 120//15 119//15 10//15
f 119//16 118//16 11//16
f 118//17 117//17 12//17
f 117//18 83//18 13//18
f 83//19 82//19 14//19
f 82//20 81//20 15//20
f 81//21 80//21 16//21
f 80//22 79//22 17//22
f 79//23 78//23 18//23
f 78//24 77//24 19//24
f 77//25 76//25 20//25
f 76//26 75//26 21//26
f 75//27 74//27 59//27
f 74//28 73//28 60//28
f 73//29 72//29 61//29
f 72//30 71//30 62//30
f 71//31 70//31 63//31
f 70//32 69//32 64//32
f 69//33 68//33 65//33
f 68//34 67//34 66//34
f 50//20 102//20 100//20
f 51//35 100//35 99//35
f 49//36 103//36 102//36
f 52//18 99//18 98//18
f 48//22 104//22 103//22
f 53//37 98//37 97//37
f 47//38 105//38 104//38
f 54//16 97//16 96//16
f 46//24 106//24 105//24
f 55//39 96//39 95//39
f 45//40 107//40 106//40
f 56//14 95//14 94//14
f 44//26 108//26 107//26
f 57//41 94//41 93//41
f 38//42 109//42 108//42
f 58//12 93//12 92//12
f 37//28 110//28 109//28
f 22//43 92//43 91//43
f 36//44 111//44 110//44
f 23//10 91//10 90//10
f 35//30 112//30 111//30
f 24//45 90//45 89//45
f 34//46 113//46 112//46
f 25//8 89//8 88//8
f 33//32 114//32 113//32
f 26//47 88//47 87//47
f 32//48 115//48 114//48
f 27//6 87//6 86//6
f 31//34 116//34 115//34
f 28//49 86//49 85//49
f 30//50 84//50 116//50
f 29//1 85//1 84//1

1 个答案:

答案 0 :(得分:3)

我要说[PDOException] SQLSTATE[HY000] [2002] No such file or directory Exception trace: () at /root/src/github.com/fashionvalet/warehouse/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:55 PDO->__construct() at /root/src/github.com/fashionvalet/warehouse/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:55 Illuminate\Database\Connectors\Connector->createConnection() at /root/src/github.com/fashionvalet/warehouse/vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php:24 Illuminate\Database\Connectors\MySqlConnector->connect() at /root/src/github.com/fashionvalet/warehouse/bootstrap/cache/compiled.php:11857 Illuminate\Database\Connectors\ConnectionFactory->createReadPdo() at /root/src/github.com/fashionvalet/warehouse/bootstrap/cache/compiled.php:11852 Illuminate\Database\Connectors\ConnectionFactory->createReadWriteConnection() at /root/src/github.com/fashionvalet/warehouse/bootstrap/cache/compiled.php:11838 Illuminate\Database\Connectors\ConnectionFactory->make() at /root/src/github.com/fashionvalet/warehouse/bootstrap/cache/compiled.php:11747 Illuminate\Database\DatabaseManager->makeConnection() at /root/src/github.com/fashionvalet/warehouse/bootstrap/cache/compiled.php:11702 Illuminate\Database\DatabaseManager->connection() at /root/src/github.com/fashionvalet/warehouse/vendor/laravel/framework/src/Illuminate/Database/Migrations/DatabaseMigrationRepository.php:171 Illuminate\Database\Migrations\DatabaseMigrationRepository->getConnection() at /root/src/github.com/fashionvalet/warehouse/vendor/laravel/framework/src/Illuminate/Database/Migrations/DatabaseMigrationRepository.php:139 Illuminate\Database\Migrations\DatabaseMigrationRepository->repositoryExists() at /root/src/github.com/fashionvalet/warehouse/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:404 Illuminate\Database\Migrations\Migrator->repositoryExists() at /root/src/github.com/fashionvalet/warehouse/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php:103 Illuminate\Database\Console\Migrations\MigrateCommand->prepareDatabase() at /root/src/github.com/fashionvalet/warehouse/vendor/orchestra/kernel/src/Database/Console/Migrations/MigrateCommand.php:40 Orchestra\Database\Console\Migrations\MigrateCommand->fire() at n/a:n/a call_user_func_array() at /root/src/github.com/fashionvalet/warehouse/bootstrap/cache/compiled.php:1257 Illuminate\Container\Container->call() at /root/src/github.com/fashionvalet/warehouse/vendor/laravel/framework/src/Illuminate/Console/Command.php:169 Illuminate\Console\Command->execute() at /root/src/github.com/fashionvalet/warehouse/vendor/symfony/console/Command/Command.php:256 Symfony\Component\Console\Command\Command->run() at /root/src/github.com/fashionvalet/warehouse/vendor/laravel/framework/src/Illuminate/Console/Command.php:155 Illuminate\Console\Command->run() at /root/src/github.com/fashionvalet/warehouse/vendor/symfony/console/Application.php:794 Symfony\Component\Console\Application->doRunCommand() at /root/src/github.com/fashionvalet/warehouse/vendor/symfony/console/Application.php:186 Symfony\Component\Console\Application->doRun() at /root/src/github.com/fashionvalet/warehouse/vendor/symfony/console/Application.php:117 Symfony\Component\Console\Application->run() at /root/src/github.com/fashionvalet/warehouse/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:107 Illuminate\Foundation\Console\Kernel->handle() at /root/src/github.com/fashionvalet/warehouse/artisan:35 导致你的问题。首先,你的法线只有3个,而不是4个。我敢打赌这会导致glDrawArrays访问超出范围的内存。

另外,因为你的法线没有正确行走,你可能会得到垃圾,这会导致某些闪烁。

因为法线紧密包装,所以只需使用0作为步幅。