Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Problem with OpenGL  (Read 2456 times)

0 Members and 1 Guest are viewing this topic.

i514x

  • Newbie
  • *
  • Posts: 15
    • View Profile
Problem with OpenGL
« on: July 23, 2012, 06:08:33 pm »
Hi all,

For a long time I've been trying to write myself a little game with no success. I finally found this library and I've downloaded 1.6 version, everything was great but my program was crashing with some App stack error when closing so I've downloaded 2.0 and I run into some problems. I used the tutorial on OpenGL for 2.0 and I put code for drawing a triangle and a square from NeHe tutorials but I get a black screen, when I comment glTranslatef the shapes show up one on top of the other so I googled glTranslatef not working and I found this topic http://www.opengl.org/discussion_boards/showthread.php/129644-glTranslatef-not-working except I am not using glut. Any ideas how can I fix this?

regards, i514x

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Problem with OpenGL
« Reply #1 on: July 23, 2012, 06:19:28 pm »
Can you show your code?
Laurent Gomila - SFML developer

i514x

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Problem with OpenGL
« Reply #2 on: July 23, 2012, 06:41:38 pm »
Ok sry dude

#pragma comment(lib, "sfml-window.lib")
#pragma comment(lib, "sfml-system.lib")
#pragma comment(lib, "sfml-graphics.lib")
#pragma comment(lib, "OpenGL32.lib")

#include <SFML/Window.hpp>
#include <SFML/OpenGL.hpp>

int main()
{
    // create the window
    sf::Window window(sf::VideoMode(800, 600), "OpenGL", sf::Style::Default, sf::ContextSettings(32));
    window.setVerticalSyncEnabled(true);

    // load resources, initialize the OpenGL states, ...

    // run the main loop
    bool running = true;
    while (running)
    {
        // handle events
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
            {
                // end the program
                running = false;
            }
            else if (event.type == sf::Event::Resized)
            {
                // adjust the viewport when the window is resized
                glViewport(0, 0, event.size.width, event.size.height);
            }
        }

        // clear the buffers
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        // draw...
                glLoadIdentity();                       // Reset The View
                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
                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

        // end the current frame (internally swaps the front and back buffers)
        window.display();
    }

    // release resources...

    return 0;
}
It's basically the same as here: http://www.sfml-dev.org/tutorials/2.0/window-opengl.php + shape drawing code from here: http://nehe.gamedev.net/tutorial/your_first_polygon/13002/


Also in the Window title some strange symbols appear before "OpenGL" text
« Last Edit: July 23, 2012, 07:37:39 pm by Laurent »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Problem with OpenGL
« Reply #3 on: July 23, 2012, 07:38:54 pm »
You must link to debug libraries (sfml-system-d.lib, etc.) in debug mode.
Laurent Gomila - SFML developer

i514x

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Problem with OpenGL
« Reply #4 on: July 23, 2012, 07:47:14 pm »
Ok thanks mate the title is now normal, but I still get the black window. In short, I think glTranslatef doesn't work properly.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Problem with OpenGL
« Reply #5 on: July 23, 2012, 08:41:40 pm »
Your code doesn't create a depth buffer (see the doc of sf::ContextSettings), and you don't define the clear depth and color (glClearColor, glClearDepth). Or you can simply disable depth testing (glDisable(GL_DEPTH_TEST)), since this small example doesn't need depth buffering (all Z are equal).
Laurent Gomila - SFML developer