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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - sfml_fan

Pages: [1]
1
Graphics / Re: sf::VertexArray and glTranslate
« on: September 23, 2013, 08:53:22 am »
Unless of course my program has memory management it needs to do at the end.  Sure this one doesn't, but I am a bit picky about doing my best to clean things up.  Sorry that I left that (in your mind) disturbing code around.  Feel free to see similar examples of "bad" programming in the openssl library :)

I went and read the Events tutorial as you suggested, but it seems to me that whether or not one should "mix events and real-time input" is really up to the programmer.  The example in which one should *not* do such things is when expecting to have smooth movement/high level responsiveness take place.  Clearly the sf::Keyboard::Escape has nothing to do with anticipating or expecting smooth and timely responsiveness. 

I don't think you were trying to be this way, but I found your tone slightly pretentious.  I would recommend in the future that you refrain from telling people "how to code" and try to stay focused on the task of helping them understand SFML itself.

2
Graphics / Re: sf::VertexArray and glTranslate
« on: September 22, 2013, 06:59:59 am »
Well for #1 sf::Transform is what I had to use in order to shift the vertex array object around the screen.

3
Graphics / sf::VertexArray and glTranslate
« on: September 22, 2013, 04:12:13 am »
1) I just started using the sf::VertexArray class.  From what I can tell glTranslate is not "compatible".  I cannot seem to move the vertex array object around the screen using glTranslate.  Should I be using sf::Transform to reposition the object? 

2) In order to draw a triangle using raw opengl while also drawing an object with sf::VertexArray, I *have* to wrap the VA call with window.pushGLStates(); window.popGLStates(); lines.  Does anybody know why this is the case?

#include <SFML/Graphics.hpp>
#include <GL/gl.h>
#include <GL/glu.h>

int main() {
  std::vector<sf::VideoMode> VModes = sf::VideoMode::getFullscreenModes();
  sf::RenderWindow window(sf::VideoMode(VModes[0].width, VModes[0].height), "SFML window", sf::Style::Fullscreen);
  window.setFramerateLimit(60);

  glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  glClearDepth(1.0);
  glDepthFunc(GL_LESS);
  glEnable(GL_DEPTH_TEST);
  glShadeModel(GL_SMOOTH);
 
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(45.0f,(GLfloat)VModes[0].width/(GLfloat)VModes[0].height,0.1f,100.0f);
 
  glMatrixMode(GL_MODELVIEW);
   
  while (1) {
    sf::Event event;
    while(window.pollEvent(event)) {
      if(event.type == sf::Event::Closed)                  { goto CLEANUP; }
      if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) { goto CLEANUP; }
    }
    window.clear();
 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
 
    glTranslatef(0.0f,0.0f,-6.0f);
 
    // triangle
    glBegin(GL_POLYGON);
    glVertex3f( 0.0f, 1.0f, 0.0f);
    glVertex3f( 1.0f,-1.0f, 0.0f);
    glVertex3f(-1.0f,-1.0f, 0.0f);
    glEnd();

    window.pushGLStates();
    glTranslatef(3.0f, 0.0f, 0.0f);
 
    // another triangle that ignores glTranslatef on my machine from what i can tell
    sf::VertexArray triangle(sf::Triangles, 3);
    triangle[0].position = sf::Vector2f(100, 100);
    triangle[1].position = sf::Vector2f(200, 100);
    triangle[2].position = sf::Vector2f(200, 200);
    triangle[0].color    = sf::Color::Red;
    triangle[1].color    = sf::Color::Blue;
    triangle[2].color    = sf::Color::Green;
    window.draw(triangle);
 
    window.popGLStates();
     
    window.display();
  }
  if(0) {
CLEANUP:
    window.close();
    return EXIT_SUCCESS;
  }
  return EXIT_FAILURE;
}
 

4
Graphics / Re: Possible Bug SFML 2.0 RC
« on: July 17, 2012, 12:54:29 pm »
It was my fault, I believe.

I am trying to use VBOs in my application and something about window.close, if called before I release the vbo memory seemed to be giving me issues.

Thanks!

5
Graphics / Possible Bug SFML 2.0 RC [Solved]
« on: July 09, 2012, 12:19:19 pm »
I'm not sure where to report this.  Sometimes exiting will lead to a seg fault.  Using gdb, I am getting the following backtrace:

Program received signal SIGSEGV, Segmentation fault.
0x0000003a3ea7925c in _int_free (av=0x3a3ed951e0, p=0x31fa7a0, have_lock=0) at malloc.c:4973
4973      unlink(nextchunk, bck, fwd);
(gdb) backtrace
#0  0x0000003a3ea7925c in _int_free (av=0x3a3ed951e0, p=0x31fa7a0, have_lock=0) at malloc.c:4973
#1  0x00007ffff70628ac in _mesa_reference_buffer_object (ctx=0x28f6d00, ptr=0x7fffffffd908, bufObj=0x0) at main/bufferobj.c:279
#2  0x00007ffff6fb7b3e in delete_bufferobj_cb (id=<optimized out>, data=<optimized out>, userData=0x28f6d00) at main/shared.c:206
#3  0x00007ffff6f8a517 in _mesa_HashDeleteAll (table=0x268ee00, callback=0x7ffff6fb7b00 <delete_bufferobj_cb>, userData=0x28f6d00) at main/hash.c:295
#4  0x00007ffff6fb7e3b in free_shared_state (shared=0x2661100, ctx=0x28f6d00) at main/shared.c:345
#5  _mesa_release_shared_state (ctx=0x28f6d00, shared=0x2661100) at main/shared.c:418
#6  0x00007ffff6f5e1a9 in _mesa_free_context_data (ctx=0x28f6d00) at main/context.c:1145
#7  0x00007ffff6ff334d in st_destroy_context (st=0x2928910) at state_tracker/st_context.c:255
#8  0x00007ffff6f37c1d in dri_destroy_context (cPriv=<optimized out>) at dri_context.c:135
#9  0x00007ffff6f17ba0 in driDestroyContext (pcp=0x26cad50) at ../common/dri_util.c:588
#10 0x0000003c5544e545 in dri2_destroy_context (context=0x275edd0) at dri2_glx.c:129
#11 0x00007ffff7932b70 in sf::priv::GlxContext::~GlxContext() () from /usr/local/lib/libsfml-window.so.2
#12 0x00007ffff7932bf9 in sf::priv::GlxContext::~GlxContext() () from /usr/local/lib/libsfml-window.so.2
#13 0x00007ffff792ec67 in sf::priv::GlContext::globalCleanup() () from /usr/local/lib/libsfml-window.so.2
#14 0x00007ffff792ef5d in sf::GlResource::~GlResource() () from /usr/local/lib/libsfml-window.so.2
#15 0x00000000004026ad in main () at main.cpp:114

Is this just an issue with my video driver?

Linux
VGA compatible controller: ATI Technologies Inc M96 [Mobility Radeon HD 4650]

6
General discussions / Is this considered a bug? (SFML 2.0)
« on: May 17, 2012, 09:34:21 am »
Calling window.pushGLStates and then popGLStates doesn't set the glMatrixMode properly.  Well, I an OpenGL newbie so I'm not sure if this is expected or not.  Basically, writing text to the window requires me to use push/pop, but pop doesn't return me to my previously expected state!

g++ main.cpp -lsfml-graphics -lsfml-audio -lsfml-window -lsfml-graphics -lsfml-system  -lglut -lGLU -lGL -lm -o run

#include <GL/gl.h>
#include <GL/glu.h>

int main() {
    sf::RenderWindow window(sf::VideoMode(800, 800), "SFML window");
 
    sf::Font font;
    if (!font.loadFromFile("tahoma.ttf"))
      return EXIT_FAILURE;
    sf::Text text("Hello SFML", font, 50);
 
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f, 2.f, 0.1f, 100.0f);
    glMatrixMode(GL_MODELVIEW);
 
    int i = 0;
    while (window.isOpen()) {
      i++;
 
      window.setActive();
      if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) {
        window.close();
      }
      window.clear();
 
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
      glLoadIdentity();
      glTranslatef(0.f,0.0f,-1.0f * i);
 
      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();
 
      window.pushGLStates();
      window.draw(text);
      window.popGLStates();

      //  Why is this required?
      glMatrixMode(GL_MODELVIEW);

      window.display();
    }
    return EXIT_SUCCESS;
  }

 

At the end of main, I have to call

glMatrixMode(GL_MODELVIEW);

in order to get "movement" working.  If you comment out the line, you will see a static screen.  If you uncomment the line, you will see the triangle fade into the distance.

7
General / Re: Text overwrites anything I draw to screen (SFML 2)
« on: May 17, 2012, 08:23:27 am »
Ok I figured it out after reading this:

http://www.sfml-dev.org/documentation/2.0/classsf_1_1RenderWindow.php#details

A working example of main is below for future reference :)


int main() {
    sf::RenderWindow window(sf::VideoMode(800, 800), "SFML window");
 
    sf::Font font;
    if (!font.loadFromFile("tahoma.ttf"))
      return EXIT_FAILURE;
    sf::Text text("Hello SFML", font, 50);
 
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f, 2.f, 0.1f, 100.0f);
    glMatrixMode(GL_MODELVIEW);
 
    while (window.isOpen()) {
      window.setActive();
      if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) {
        window.close();
      }
      window.clear();
 
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
      glLoadIdentity();
      glTranslatef(0.f,0.0f,-6.0f);

      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();
 
      window.pushGLStates();
      window.draw(text);
      window.popGLStates();
.
      window.display();
    }
    return EXIT_SUCCESS;
  }

 

8
I cannot print text and opengl primitives to screen at the same time.

In the code below simply comment out the call for drawing text to screen in order to see the triangle.

  #include <stdio.h>
  #include <SFML/Audio.hpp>
  #include <SFML/Graphics.hpp>
  #include <GL/gl.h>
  #include <GL/glu.h>
 
  int main() {
    sf::RenderWindow window(sf::VideoMode(800, 800), "SFML window");
 
    sf::Font font;
    if (!font.loadFromFile("tahoma.ttf"))
      return EXIT_FAILURE;
    sf::Text text("Hello SFML", font, 50);
 
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);  
    glClearDepth(1.0);        
    glDepthFunc(GL_LESS);      
    glEnable(GL_DEPTH_TEST);      
    glShadeModel(GL_SMOOTH);      
 
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();      
    gluPerspective(45.0f, 2.f, 0.1f, 100.0f);
    glMatrixMode(GL_MODELVIEW);
 
    while (window.isOpen()) {
      window.setActive();
      if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) {
        window.close();
      }
      window.clear();
 
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
      glLoadIdentity();      
.     glTranslatef(0.f,0.0f,-6.0f);
 
     //COMMENT OUT THIS LINE
      window.draw(text);

      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();
 
      window.display();
    }
    return EXIT_SUCCESS;
  }


 

So if I comment out the "window.draw(text)" line, then I can see a triangle on screen.  If I don't comment it out, I see the text "Hello SMFL" without a triangle on screen.

What am I doing wrong?

Fedora 15
SFML 2.0

Pages: [1]
anything