2011-05-16 6 views
0

방금 ​​VBO (SDL/glew 사용)를 사용하기 시작했습니다. 실제로 현재 큐브의 단지 하나의 얼굴 - - 나는 큐브의 간단한 예제를 사용하여 시작하기 위해 노력하고있어하지만 다음과 같이 내 정점 구조가 정의VBO가 표시되지 않습니다 (glew와 함께 sdl)

표시 아무것도 얻을 수 없습니다

struct Vertex 
{ 
float x, y, z;   //Vertex coords 
float tx, ty;   //Texture coords 
float nx, ny, nz;  //Normal coords 
}; 

큐브는 다음과 같이 생성된다 :

후 별도의 함수로 렌더링하도록 보내
 Vertex temp; 

     //NOTE: Perspective is from looking at the cube from the outside 
    //Just trying to display one face for the moment to simplify 
     //Back face ------------------------------------------------------------------------------------------ 
     temp.x = 0.f; temp.y = 0.f; temp.z = 0.f;  //Bottom Right - 0 
     temp.nx = 0.f; temp.ny = 0.f; temp.nz = 1.f; // This stays the same for the rest of the face 
     temp.tx = 1.f; temp.ty = 0.f; 
     m_vertices.push_back(temp); 

     temp.x = 0.f; temp.y = m_fHeight; temp.z = 0.f;   //Top Right - 1 
     temp.tx = 1.f; temp.ty = 1.f; 
     m_vertices.push_back(temp); 

     temp.x = m_fWidth; temp.y = m_fHeight; temp.z = 0.f; //Top Left  - 2 
     temp.tx = 0.f; temp.ty = 1.f; 
     m_vertices.push_back(temp); 

     temp.x = m_fWidth; temp.y = 0.f; temp.z = 0.f; //Bottom Left - 3 
     temp.tx = 0.f; temp.ty = 0.f; 
     m_vertices.push_back(temp); 

     m_indeces.push_back(0); m_indeces.push_back(1); m_indeces.push_back(2); 
     m_indeces.push_back(2); m_indeces.push_back(3); m_indeces.push_back(0); 


     //Generate the vertex buffer 
     glGenBuffers(1, &m_vertexBufferID); 
     //Bind the vertex buffer                         
     glBindBuffer(GL_ARRAY_BUFFER, m_vertexBufferID); 
     //Fill the vertex buffer - size is 24*sizeof(Vertex) bcs 6 faces with 4 corners 
     glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * 4, NULL, GL_STATIC_DRAW); 
     glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(Vertex) * 4, &m_vertices); // Actually upload the data 

     //Set up the pointers 
     glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET(12)); 
     glNormalPointer(GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET(20)); 
     glVertexPointer(3, GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET(0)); 


     //Generate the index buffer 
     glGenBuffers(1, &m_indexBufferID);          
     //Bind the index buffer                       
     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBufferID); 
     //Fill the index buffer- size is 36*sizeof(uint) bcs 6 traingle coords in 1 face * 6 faces 
     glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLubyte) * 6, NULL, GL_STATIC_DRAW); 
     glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(GLubyte) * 6, &m_indeces); // Actually upload the data 

:

glBindBuffer(GL_ARRAY_BUFFER, vertexID); 
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexID); 

glEnableClientState(GL_TEXTURE_COORD_ARRAY); 
glEnableClientState(GL_NORMAL_ARRAY); 
glEnableClientState(GL_VERTEX_ARRAY); 

// Resetup the pointers. 
glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET(12)); 
glNormalPointer(GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET(20)); 
glVertexPointer(3, GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET(0)); 

//Draw the indexed elements 
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0)); 

glDisableClientState(GL_TEXTURE_COORD_ARRAY); 
glDisableClientState(GL_NORMAL_ARRAY); 
glDisableClientState(GL_VERTEX_ARRAY); 
- 직접 모드에서 큐브 같은 질감 등을 적용하는 벌금을 나타

// A helper macro to get a position 
#define BUFFER_OFFSET(i) ((char *)NULL + (i)) 

하지만 난 그냥 표시 아무것도 얻을 수 없습니다

및 BUFFER_OFFSET()는 simaple 매크로로 정의된다.

이상한 점은 때마다 매우 이상한 것이 표시 될 것입니다. 이는 매번 달라지기 때문에 일종의 초기화 오류일까요?

+0

"색인"은 "색인"또는 "색인"입니다. –

+0

glGetError()는 무엇을 말합니까? –

+0

VBO가 없으면'glDrawElements'가 작동합니까? –

답변

0

의견과 일치하는 크기가 없으므로 VBO가 끝났습니다.

+0

안녕하세요, 미안 해요 분명히 의견을 기각하는 것을 잊어 버렸습니다 - 저는 현재 크기가 정확하다고 생각합니다. 왜냐하면 저는 4 개의 버텍스 구조체에 의해 설명되어야하는 한 얼굴 만 렌더링하려고하기 때문입니다 (전체 큐브 x6 얼굴) 똑같은 것은 indeces의 수를 간다 – woofbluddywoof

1

Huzzah !! &m_vertices&m_indecesm_verticesm_indeces으로 변경하면 glBufferSubData()이 호출됩니다.

a-thank-yoh!

+1

답을 수락하는 것을 잊지 마십시오. – genpfault

관련 문제