私はVBOを使用してOpenGLで作業しており、3本の線のセットがあります(X、Y、Z軸に沿って-チェコのハリネズミだと思います)。線はデフォルトではグレーですが、見やすいように明るい赤にします。残念ながら、頂点データとして色情報を追加しましたが、線はまだ灰色に見えます。おそらく基本的な何かが欠けているのですが、見えません。VBO の作成方法は次のとおりです。
//Position data
sf::Vector3<float> Top = sf::Vector3<float>(0.0, 1.0, 0.0);
sf::Vector3<float> Front = sf::Vector3<float>(0.0, 0.0, -1.0);
sf::Vector3<float> Right = sf::Vector3<float>(1.0, 0.0, 0.0);
sf::Vector3<float> Back = sf::Vector3<float>(0.0, 0.0, 1.0);
sf::Vector3<float> Left = sf::Vector3<float>(-1.0, 0.0, 0.0);
sf::Vector3<float> Bottom = sf::Vector3<float>(0.0, -1.0, 0.0);
//Color data
//Just to be clear, I also tried with 255.0, although I'm rather certain OpenGL
//does its colors on a 0-1 scale.
sf::Vector3<float> Color = sf::Vector3<float>(1.0, 0.0, 0.0);
//Create vector
std::vector<float> LineArray;
//Top
LineArray.push_back(Top.x);
LineArray.push_back(Top.y);
LineArray.push_back(Top.z);
LineArray.push_back(Color.x);
LineArray.push_back(Color.y);
LineArray.push_back(Color.z);
//Bottom
LineArray.push_back(Bottom.x);
LineArray.push_back(Bottom.y);
LineArray.push_back(Bottom.z);
LineArray.push_back(Color.x);
LineArray.push_back(Color.y);
LineArray.push_back(Color.z);
//Front
LineArray.push_back(Front.x);
LineArray.push_back(Front.y);
LineArray.push_back(Front.z);
LineArray.push_back(Color.x);
LineArray.push_back(Color.y);
LineArray.push_back(Color.z);
//Back
LineArray.push_back(Back.x);
LineArray.push_back(Back.y);
LineArray.push_back(Back.z);
LineArray.push_back(Color.x);
LineArray.push_back(Color.y);
LineArray.push_back(Color.z);
//Right
LineArray.push_back(Right.x);
LineArray.push_back(Right.y);
LineArray.push_back(Right.z);
LineArray.push_back(Color.x);
LineArray.push_back(Color.y);
LineArray.push_back(Color.z);
//Left
LineArray.push_back(Left.x);
LineArray.push_back(Left.y);
LineArray.push_back(Left.z);
LineArray.push_back(Color.x);
LineArray.push_back(Color.y);
LineArray.push_back(Color.z);
//Create buffer
glGenBuffers(1, &m_Buffer);
glBindBuffer(GL_ARRAY_BUFFER, m_Buffer);
int SizeInBytes = LineArray.size() * 6 * sizeof(float);
glBufferData(GL_ARRAY_BUFFER, SizeInBytes, NULL, GL_STATIC_DRAW);
//Upload buffer data
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float) * LineArray.size(), &LineArray[0]);
そして、これは私がすべての目盛りを表示する方法です:
glPushMatrix();
//Translate
glTranslatef(m_Position.x, m_Position.y, m_Position.z);
//Rotate
glMultMatrixf(m_RotationMatrix);
//Bind buffers for vertex and color arrays
glBindBuffer(GL_ARRAY_BUFFER, m_Buffer);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 6 * sizeof(float), 0);
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(3, GL_FLOAT, 6 * sizeof(float), (void*)12);
//Draw
glDrawArrays(GL_LINES, 0, 36);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
//Unbind the buffers
glBindBuffer(GL_ARRAY_BUFFER, 0);
glPopMatrix();
以前に GL_COLOR_ARRAY を使用したことはありませんが、コードは GL_NORMAL_ARRAY の使用に成功したことに基づいています。誰かが間違っていることを指摘できますか?
編集:基本的なOpenGLパラメータを間違って設定している可能性があります(特に照明)。これらは次のとおりです。
m_AmbientLight = {0.5f, 0.5f, 0.5f, 1.0f};
m_DiffuseLight = {1.0f, 1.0f, 1.0f, 1.0f};
m_LightPos = {8.0f, -16.0f, 8.0f, 0.0f};
//Smooth Shading
glShadeModel(GL_SMOOTH);
// Set color and depth clear value
glClearDepth(1.f);
//Color here is in RGB, converted to a 0-1 scale.
glClearColor(0.3f, 0.3f, 0.3f, 1.f);
// Enable Z-buffer read and write
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
///
///LIGHTING
///
//Set up lighting.
//This activates the ambient light.
glLightfv(GL_LIGHT0, GL_AMBIENT, m_AmbientLight);
//This activates the diffuse light.
glLightfv(GL_LIGHT1, GL_DIFFUSE, m_DiffuseLight);
//This sets the position of the diffuse light.
glLightfv(GL_LIGHT1, GL_POSITION, m_LightPos);
//This enables the light.
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
//Enables all lighting...?
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
//glEnable(GL_NORMALIZE);
// Setup a perspective projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.f, 1.33f, 0.1f, 512.f);
EDIT 2: glColor3f() も効果がないことを確認したので、シェーダーに問題があるのではないかと思います:
頂点シェーダー:
void main()
{
vec3 normal, lightDir;
vec4 diffuse;
float NdotL;
normal = normalize(gl_NormalMatrix * gl_Normal);
lightDir = normalize(vec3(gl_LightSource[0].position));
NdotL = max(dot(normal, lightDir), 0.0);
diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;
gl_FrontColor = NdotL * diffuse;
gl_Position = ftransform();
}
フラグ シェーダ:
void main()
{
gl_FragColor = gl_Color;
}