非常に単純なシェーダーを OpenGL に実装しようとしています。残念ながら、私は次のことに遭遇し続けます:
Cannot access private member declared in class 'sf::NonCopyable
私は自分でこれを理解しようとしましたが、どこかで sf::Shader を宣言し直していると思います。
sf::Shader compile_shaders(void)
{
sf::Shader shader;
const std::string vertex_shader_source = \
"#version 430 core "\
" "\
"void main(void){ "\
" gl_position = vec4(0.0, 0.0, 0.5, 1.0);"\
"} ";
const std::string fragment_shader_source = \
"#version 430 core "\
" "\
"out vec4 color; "\
" "\
"void main(void){ "\
" color = vec4(0.0, 0.8, 1.0, 1.0);"\
"} ";
shader.loadFromMemory(vertex_shader_source, fragment_shader_source);
return shader;
}
int main(){
int width = 800;
int height = 450;
sf::Window window(sf::VideoMode(width, height), "OpenGL Test", sf::Style::Default, sf::ContextSettings(32));
resize(width, height);
init();
window.setVerticalSyncEnabled(true);
sf::Shader shader = compile_shaders();
bool running = true;
while (running){
sf::Event event;
while (window.pollEvent(event)){
if (event.type == sf::Event::Closed)
running = false;
else if (event.type == sf::Event::Resized){
width = event.size.width;
height = event.size.height;
resize(width, height);
}
else if (event.type == sf::Event::KeyPressed & event.key.code == sf::Keyboard::Escape)
running = false;
}
sf::Shader::bind(&shader);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(-1.5f,0.0f,-6.0f);
glBegin(GL_TRIANGLES);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glEnd();
glTranslatef(3.0f, 0.0f, 0.0f);
glColor3f(0.5f,0.5f,1.0f);
glBegin(GL_QUADS);
glVertex3f(-1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();
window.display();
sf::Shader::bind(NULL);
}
return 0;
}
resize() と init() はいくつかの OpenGL 変数を設定しているだけなので、問題はないと確信しています。