So, what I know:
- SFML does open me a window
- I do get an OpenGL 3.2 context (from glew)
- the camera-position-data sent to gluLookAt() is correct
- I get the background color that I specified
- That's all I get. No polygons in sight.
// Init SFML
sf::VideoMode mode;
mode.Width = 1024;
mode.Height = 768;
mode.BitsPerPixel = 32;
sf::ContextSettings settings;
settings.DepthBits = 32;
settings.StencilBits = 8;
settings.AntialiasingLevel = 2;
settings.MajorVersion = 3;
settings.MinorVersion = 2;
App = new sf::Window(mode, "SFML OpenGL", sf::Style::Close, settings);
App->Create(mode, "SFML OpenGL", sf::Style::Close, settings);
App->SetActive();
Input = &(App->GetInput());
if(glewInit() != GLEW_OK){
std::cout<<"Glew Init Error!";
}
GLuint vboID;
glGenBuffers(0, &vboID);
std::cout<<"Glew version: "<<glewGetString(GLEW_VERSION)<<"\n";
if (GLEW_VERSION_3_2){ std::cout<<"OpenGL 3.2!\n";}
std::cout<<"glGenBuffers: "<< glGenBuffers <<"\n\n";
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do
glDepthMask(GL_TRUE);
glShadeModel(GL_SMOOTH); // Enables Smooth Shading
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Perspective Calculations
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glViewport(0, 0, mode.Width, mode.Height);
gluPerspective(45.f, (GLfloat)(mode.Width/mode.Height), 0.1f, 100.0f);
std::cout<<"Open window:"<<mode.Width<<"x"<<mode.Height<<" \n";
glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f );
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
And here's the renderloop, with a lot of extra muck in the spirit of "If I just throw a lot of stuff to OpenGL I'm sure not to miss any".
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
Vec3 p = camera->getPos();
Vec3 l = camera->getDirection();
Vec3 u = camera->upDirection;
glViewport(0, 0, 1000, 1000); // Reset The Current Viewport
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
gluLookAt(p.x,-p.y,p.z,
l.x,-l.y,l.z,
u.x,-u.y,u.z);
camera->frustum.setCamDef(p,l,u);
glClearColor ( 0.2f, 0.2f, 0.4f, 0.0f );
glColor3f(1.0f, 1.0f, 1.0f);
glTranslatef(-1.5f,0.0f,-6.0f); // Left 1.5 Then Into Screen Six Units
glBegin(GL_TRIANGLES); // Begin Drawing Triangles
glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red
glVertex3f( 0.0f, 1.0f, 0.0f); // Move Up One Unit From Center (Top Point)
glColor3f(0.0f,1.0f,0.0f); // Set The Color To Green
glVertex3f(-1.0f,-1.0f, 0.0f); // Left And Down One Unit (Bottom Left)
glColor3f(0.0f,0.0f,1.0f); // Set The Color To Blue
glVertex3f( 1.0f,-1.0f, 0.0f); // Right And Down One Unit (Bottom Right)
glEnd(); // Done Drawing A Triangle
glTranslatef(3.0f,0.0f,0.0f); // From Right Point Move 3 Units Right
glColor3f(0.5f,0.5f,1.0f); // Set The Color To Blue One Time Only
glBegin(GL_QUADS); // Start Drawing Quads
glVertex3f(-1.0f, 1.0f, 0.0f); // Left And Up 1 Unit (Top Left)
glVertex3f( 1.0f, 1.0f, 0.0f); // Right And Up 1 Unit (Top Right)
glVertex3f( 1.0f,-1.0f, 0.0f); // Right And Down One Unit (Bottom Right)
glVertex3f(-1.0f,-1.0f, 0.0f); // Left And Down One Unit (Bottom Left)
glEnd();
App->Display();