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

Author Topic: Error using SFML  (Read 1263 times)

0 Members and 1 Guest are viewing this topic.

thrasher66099

  • Newbie
  • *
  • Posts: 1
    • AOL Instant Messenger - 214+Tanager+Ct
    • View Profile
Error using SFML
« on: January 26, 2011, 02:53:21 am »
I have setup sfml to use as my window wrapper and it works when I run the following code

Code: [Select]

#include <SFML/System.hpp>
#include <iostream>

int main()
{
    sf::Clock Clock;
    while (Clock.GetElapsedTime() < 5.f)
    {
        std::cout << Clock.GetElapsedTime() << std::endl;
        sf::Sleep(0.5f);
    }

    return 0;
}


But when I try to create an application window I am getting the following error when I begin debugging it:

Unhandled exception at 0x76de1e04 in OpenGL test.exe: 0xC0000005: Access violation reading location 0x65704f20.

OpenGL test is the name of the solution obviously. This exception gets thrown when it tries to run the first line of code in the main function of the following snippet:

Code: [Select]
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <gl/GL.h>
#include <gl/GLU.h>
#include <iostream>

int main(int argc, char** argv)
{

 sf::Window App(sf::VideoMode(800, 600, 32), "SFML OpenGL");

 // Set color and depth clear value
 glClearDepth(1.f);
 glClearColor(0.f, 0.f, 0.f, 0.f);

 // Enable Z-buffer read and write
 glEnable(GL_DEPTH_TEST);
 glDepthMask(GL_TRUE);

 // Setup a perspective projection
 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 gluPerspective(90.f, 1.f, 1.f, 500.f);

 while (App.IsOpened())
 {
  //handle events
  sf::Event Event;
  while (App.GetEvent(Event))
  {
   if (Event.Type == sf::Event::Resized)
   glViewport(0, 0, Event.Size.Width, Event.Size.Height);
  }

  //set this window as active
  App.SetActive();
   
  //erase previous frame's content
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  //draw cube
  glBegin(GL_QUADS);

  glVertex3f(-50.f, -50.f, -50.f);
  glVertex3f(-50.f,  50.f, -50.f);
  glVertex3f( 50.f,  50.f, -50.f);
  glVertex3f( 50.f, -50.f, -50.f);

  glVertex3f(-50.f, -50.f, 50.f);
  glVertex3f(-50.f,  50.f, 50.f);
  glVertex3f( 50.f,  50.f, 50.f);
  glVertex3f( 50.f, -50.f, 50.f);

  glVertex3f(-50.f, -50.f, -50.f);
  glVertex3f(-50.f,  50.f, -50.f);
  glVertex3f(-50.f,  50.f,  50.f);
  glVertex3f(-50.f, -50.f,  50.f);

  glVertex3f(50.f, -50.f, -50.f);
  glVertex3f(50.f,  50.f, -50.f);
  glVertex3f(50.f,  50.f,  50.f);
  glVertex3f(50.f, -50.f,  50.f);

  glVertex3f(-50.f, -50.f,  50.f);
  glVertex3f(-50.f, -50.f, -50.f);
  glVertex3f( 50.f, -50.f, -50.f);
  glVertex3f( 50.f, -50.f,  50.f);

  glVertex3f(-50.f, 50.f,  50.f);
  glVertex3f(-50.f, 50.f, -50.f);
  glVertex3f( 50.f, 50.f, -50.f);
  glVertex3f( 50.f, 50.f,  50.f);

  glEnd();

  App.Display();
 }

    return 0;

}



Does anyone have any idea what I might be doing wrong?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Error using SFML
« Reply #1 on: January 26, 2011, 07:36:53 am »
Possible causes:
- you use VC++ 2010 but didn't recompile SFML
- you compile as 64 bits but didn't recompile SFML
- you're using release libraries in debug mode
Laurent Gomila - SFML developer

 

anything