SFML/OpenGL draw nothing

Hi, I am absolute beginner in OpenGL and 3D and I am trying to write basic program from first article NeHe tutorials
,but I am using SFML for window and other stuff, but it doesn’t work, please can somebody check my code? Thanks a lot for any help :frowning:

#include <SFML/Window.hpp>

int InitGL(void)                              // All Setup For OpenGL Goes Here
{
   glShadeModel(GL_SMOOTH);                     // Enable Smooth Shading
   glClearColor(0.0f, 0.0f, 0.0f, 1.0f);            // Black Background
   glClearDepth(1.0f);                           // Depth Buffer Setup
   glEnable(GL_DEPTH_TEST);                     // Enables Depth Testing
   glDepthFunc(GL_LEQUAL);                        // The Type Of Depth Testing To Do
   glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);   // Really Nice Perspective Calculations
   return 1;                              // Initialization Went OK
}

int DrawGLScene(void)                           // Here's Where We Do All The Drawing
{
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);   // Clear Screen And Depth Buffer
   glLoadIdentity();                           // Reset The Current Modelview Matrix
   glTranslatef(-1.5f,0.0f,-6.0f);                  // Move Left 1.5 Units And Into The Screen 6.0
   glBegin(GL_TRIANGLES);                        // Drawing Using Triangles
      glVertex3f( 0.0f, 1.0f, 0.0f);               // Top
      glVertex3f(-1.0f,-1.0f, 0.0f);               // Bottom Left
      glVertex3f( 1.0f,-1.0f, 0.0f);               // Bottom Right
   glEnd();                                 // Finished Drawing The Triangle
   glTranslatef(3.0f,0.0f,0.0f);                  // Move Right 3 Units
   glBegin(GL_QUADS);                           // Draw A Quad
      glVertex3f(-1.0f, 1.0f, 0.0f);               // Top Left
      glVertex3f( 1.0f, 1.0f, 0.0f);               // Top Right
      glVertex3f( 1.0f,-1.0f, 0.0f);               // Bottom Right
      glVertex3f(-1.0f,-1.0f, 0.0f);               // Bottom Left
   glEnd();                                 // Done Drawing The Quad
   return 1;                              // Everything Went OK
}

int main()
{
    // Create the main window
    sf::Window App(sf::VideoMode(800, 600, 32), "SFML OpenGL");

    InitGL();

    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();

            // Escape key : exit
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
                App.Close();

            // Resize event : adjust viewport
            if (Event.Type == sf::Event::Resized)
                glViewport(0, 0, Event.Size.Width, Event.Size.Height);
        }

        DrawGLScene();
        App.Display();
    }

    return 0;
}

Three things,

  1. Don’t modify the depth func just enable depth test in other words comment the 2 lines

//glClearDepth(1.0f);        
glEnable(GL_DEPTH_TEST);
//glDepthFunc(GL_LEQUAL);  

  1. You have not setup your projection matrix usually u would add in a resize handler like this,

void OnResize(int nw, int nh) {
  glViewport(0, 0, nw, nh);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(60,float(nw)/nh,0.1,100);
  glMatrixMode(GL_MODELVIEW);
}

//call it from main in the resize event like this
if (Event.Type == sf::Event::Resized)
   OnResize(Event.Size.Width, Event.Size.Height);


  1. Just move the camera 5 units on Z axis only and see if u get something. Then later change it to whatever position u want.

int DrawGLScene(void)
{
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);   
   glLoadIdentity();                           
   glTranslatef(0.0f,0.0f,-5.0f);
   ///rest of draw function
}

See if this helps. Note that I have never used SFML but this is how the GL part should be structured.

Thanks, I try learn 2D technique in OpenGL rather first :smiley: .