저는 Model이라는 클래스를 가지고 있습니다.이 클래스는 그 자체를 그리는 데 필요한 모든 정보를 처리합니다. 기본적으로 두 가지 방법이 있습니다 :클래스 생성자가 데이터를 VBO로 보내지 않습니다.
1) 컨스트럭터 - VBO, VAO 및 유니폼 직원을 만들고 초기화합니다. 2) 그리기 - VAO 바인딩 그리기 및
내 문제는 glBufferData를 사용하여 VBO를 초기화하는 것입니다. GPU 메모리에 업로드해야하는 데이터가 아닙니다. gDebugger를 사용하여 이것을 확인했습니다. 또한 내가 데이터를 다시 생성자 클래스 외부로 보내려고하면 모든 것이 잘 진행된다. 나는 무엇을 놓치고 있는가 ???
Model의 클래스 인스턴스 객체는 템플릿 매개 변수 V 및 M이 각각 vec4 및 mat4 인 전역 변수입니다.
나는 또한 Linux/Windows/NVIDIA/RADEON에서 테스트했으며 동일한 문제가 발생합니다. 셰이더 용으로 #verson 400을 사용하고 glm 수학 라이브러리를 사용했습니다.
1) 생성자 :
/** This constructor has 5 steps:
* 1) Allocate variables
* 2) Create, bind and Send vbo inf.
* 3) Create, bind vao info
* 4) Create mapping between Buffer and Attributes in GPU memory
* 5) Get uniform variables location
*
* */
template<class V, class M>
Model<V, M>::Model(GLuint size, GLuint program){
assert(size > 0);
/** BEG - 1) Allocate variables */
/** beg - model variable initialization */
this->vertex = new vec4[ size ];
this->numVertex = size;
this->color = new vec4[ size ];
this->numColor = size;
//this->element => not initialized
//this->numElem => not initialized
this->modelMatrix = M(1); // Identity Matrix
this->position = V(0); // Orign
// VBO - Vertex Buffer Object information
this->vbo = new GLuint[ this->numBuff ];
this->vboSize = this->numBuff;
// VAO - Vexter Array Object information
this->vao = new GLuint[ 1 ];
this->numVao = 1;
this->attrib = new GLuint[ this->numBuff ];
this->numAttrib = this->numBuff;
this->uniform = new string[ this->numUni ];
this->uniformLoc = new GLuint[ this->numUni ];
this->numUniform = this->numUni;
this->program = program;
//beg - Inittialization
this->attrib[VERTEX] = 0;
this->attrib[COLOR] = 1;
this->uniform[0] = string("modelMatrix");
this->uniform[1] = string("position");
//end - Inittialization
/** END - 1) Allocate variables */
/** BEG - 2) Create, bind and Send vbo inf */
// Create vbo identifier
glGenBuffers(this->vboSize, this->vbo);
Other<V>::checkError("glGenBuffers");
// Bind Buffer
glBindBuffer(GL_ARRAY_BUFFER, (this->vbo)[0]);
Other<V>::checkError("glBindBuffer");
// Send Data to buffer
glBufferData( GL_ARRAY_BUFFER, sizeof((this->vertex)[0][0]) * (this->vertex)[0].length() * (this->numVertex),
&(this->vertex[0][0]), GL_STATIC_DRAW);
Other<V>::checkError("glBufferData");
// Bind Buffer
glBindBuffer(GL_ARRAY_BUFFER, (this->vbo)[1]);
Other<V>::checkError("glBindBuffer");
// Send Data to buffer
glBufferData( GL_ARRAY_BUFFER, sizeof((this->color)[0][0]) * (this->color)[0].length() * (this->numColor),
&(this->color[0][0]), GL_STATIC_DRAW);
Other<V>::checkError("glBufferData");
/** END - 2) Create, bind and Send vbo inf */
/** BEG - 3) Create, bind and enable vao info */
// Create vao identifier
glGenVertexArrays(1, this->vao);
Other<V>::checkError("glGenVertexArrays");
glBindVertexArray((this->vao)[0]);
Other<V>::checkError("glBindVertexArray");
// Enable attributes
for (uint i=0; i<numAttrib; i++){
glEnableVertexAttribArray(i);
Other<V>::checkError("glEnableVertexAttribArray");
}
/** END - 3) Create and enable vao info */
/** BEG - 4) Create mapping between Buffer and Attributes in GPU memory */
for (uint i=0; i<numAttrib; i++){
glBindBuffer(GL_ARRAY_BUFFER, (this->vbo)[i]);
Other<V>::checkError("glBindBuffer");
glVertexAttribPointer((this->attrib)[i], (this->vertex)[i].length(), GL_FLOAT, GL_FALSE, 0, (GLubyte *)NULL);
Other<V>::checkError("glBindBuffer");
}
/** END - 4) Create mapping between Buffer and Attributes in GPU memory */
/** BEG - 5) Get uniform variables location */
for (uint i=0; i<numAttrib; i++){
this->uniformLoc[i] = glGetUniformLocation(program, this->uniform[i].c_str());
Other<V>::checkError("glGetUniformLocation");
}
/** END - 5) Get uniform variables location */
}
2)
template<class V, class M>
void Model<V, M>::draw()
{
//glUniformMatrix4fv(this->uniformLoc[0], 1, GL_FALSE, &(this->modelMatrix[0][0]));
//glUniform4fv( this->uniformLoc[1], 1, &(this->position[0]));
glBindVertexArray((this->vao)[0]);
glDrawArrays(GL_LINE_STRIP, 0, this->numVertex);
}
내가 같이 sendData 멤버 함수를 사용 생성자 후 GPU에 데이터 "재전송"그릴 여기
코드를 진행한다 :template<class V, class M>
void Model<V, M>::sendData()
{
glBindBuffer(GL_ARRAY_BUFFER, (this->vbo)[0]);
// Send Data to buffer
glBufferData( GL_ARRAY_BUFFER, sizeof((this->vertex)[0][0]) * (this->vertex)[0].length() * (this->numVertex),
&(this->vertex[0][0]), GL_STATIC_DRAW);
}
편집 : sendData 멤버 함수를 추가하는 것을 잊었습니다
감사합니다. 생성자 전에 glewInit을 호출 했었습니다. 나는 glut과 init의 모든 초기화 후에 객체 모델을 위해 새로운 것을 호출한다. 생성자 내의 모든 OpenGL 명령은 그 이후에 발행됩니다. – Caslu