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 - robrene

Pages: [1]
1
I'm not sure if this is absolutely minimal, since something in here might be causing a side effect. This code does reproduce my error though. It shows a window of 512x256, with the left half being filled with what looks like random areas of video memory.

#include <cmath>
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>

int main() {
  sf::RenderWindow window(sf::VideoMode(512, 256), "Cubetest", sf::Style::Titlebar|sf::Style::Close);
  sf::RenderTexture texture;
  texture.create(256, 256, true);

  texture.setActive(true);

  glMatrixMode(GL_PROJECTION);
  glPushMatrix();
  glLoadIdentity();
  float fov = 60.f;
  float near = 1.f / std::tan(fov / 2.f * (M_PI / 180.f)) / 100.f;
  glFrustum(-.01f, .01f, -.01f, .01f, near, 100.f);

  glMatrixMode(GL_MODELVIEW);
  glPushMatrix();
  glLoadIdentity();
  glTranslatef(.0f, .0f, -4.0f);

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glBegin(GL_TRIANGLES);
    glColor3f(1.0f, 1.0f, 1.0f);
    glVertex3f( 0.0f,  1.0f, 0.0f);
    glVertex3f(-1.0f, -1.0f, 0.0f);
    glVertex3f( 1.0f, -1.0f, 0.0f);
  glEnd();

  glPopMatrix();
  glMatrixMode(GL_PROJECTION);
  glPopMatrix();

  texture.setActive(false);

  window.pushGLStates();
  window.clear();
  sf::Sprite sprite(texture.getTexture());
  window.draw(sprite);
  window.display();
  window.popGLStates();

  sf::Event event;
  while (window.waitEvent(event) && event.type != sf::Event::Closed) {}
  window.close();
  return 0;
}

2
Ah, that must be an artifact from boiling down the code to the bare necessities. I edited my example to set it to true, the bit was set to true in the constructor on my end as part of the rest of the state which I left out in this example.

The state is not used yet when rendering, so the code is functionally the same as it is written here.

To clarify: The problem persists.

3
I'm sorry for not adding more information immediately, I was in the process of trying some stuff, but I did not have anything tangential enough that I felt it would be worth showing. I can post the current state of things.

Here are current implementation details for the base class:

GLBaseWidget::GLBaseWidget(int width, int height) : dirty_bit_(true) {
  texture_.create(width, height, true);
}

void GLBaseWidget::update() {
  if (dirty_bit_) {
    texture_.setActive(true);

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    float aspect = static_cast<float>(texture_.getTexture().getSize().x) / static_cast<float>(texture_.getTexture().getSize().y);
    float fov = 60.f;
    float near = 1.f / std::tan(fov / 2.f * (M_PI / 180.f)) / 100.f;
    glFrustum(-.01f, .01f, -.01f / aspect, .01f / aspect, near, 100.f);

    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();
    glTranslatef(.0f, .0f, -4.0f);
    // TODO: rotation here

    renderToTexture();

    glPopMatrix();
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();

    texture_.setActive(false);

    dirty_bit_ = false;
  }
}

void GLBaseWidget::draw(sf::RenderTarget& target, sf::RenderStates states) const {
  sf::Sprite sprite(texture_.getTexture());
  states.transform *= getTransform();
  target.draw(sprite, states);
}
 

Here is an example implementation that tries to draw just a triangle (PtWidget publicly inherits GLBaseWidget):

PtWidget::PtWidget(int width, int height)
: CubeWidget(width, height) {}

void PtWidget::renderToTexture() {
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glBegin(GL_TRIANGLES);
    glVertex3f( 0.0f,  1.0f, 0.0f);
    glVertex3f(-1.0f, -1.0f, 0.0f);
    glVertex3f( 1.0f, -1.0f, 0.0f);
  glEnd();
}

This is the main function that calls this code:

int main() {
  sf::RenderWindow window(sf::VideoMode(512, 256), "Cubetest", sf::Style::Titlebar|sf::Style::Close);

  PtWidget pt_widget(256, 256);
  pt_widget.setPosition(0, 0);

  while (window.isOpen()) {
    window.pushGLStates();
    window.clear();
    window.draw(pt_widget);
    window.display();
    window.popGLStates();

    sf::Event event;
    while (window.waitEvent(event)) {
      if (event.type == sf::Event::Closed) window.close();
    }

    pt_widget.update();
  }

  return 0;
}

When I run it, I get some random textures from memory (from other applications or parts of the OS) in the left half of the window. When I close the window, the application "quits unexpectedly".

4
I'm trying to create an abstract base class that allows implementations to render into a sf::RenderTexture using raw OpenGL calls. A bit like this:

class GLBaseWidget : public Drawable, public Transformable {
 public:
  void update();  // Rerenders into texture if dirty bit set
  void draw(sf::RenderTarget&, sf::RenderStates) const override;  // Draws texture sprite to target
  math::Vec2i size() const;
  void rotateBy(const math::Vec3f&);

 protected:
  GLWidget(math::Vec2i size);
  void setDirtyBit();
  virtual void doRendering() = 0;

 private:
  sf::RenderTexture texture_;
  bool dirty_bit_;
  float rotation_matrix_[16];
};

This is a simplified version. The base class holds some state (the rotation matrix for example) and methods to modify the state. The update() method is where I am having trouble.

Obviously, the update() method checks for the dirty bit first. Then I want it to set up the projection and modelview matrices before calling the virtual doRendering() method. Afterwards, the OpenGL state should be back to the way it was before calling update().

I've written similar code using OpenGL Renderbuffers once, but not with gl::RenderTexture. Can someone guide me to the necessary steps for this to work? Ideally, the implementing classes will only push the actual vertices into the pipeline and everything will work.

5
General / Having trouble solving SFML linker errors
« on: November 18, 2013, 05:20:49 pm »
Hello

I'm having trouble setting up SFML on my laptop running Ubuntu 13.10 (32 bit). I've managed to set it up successfully already on my PC running Arch Linux (64 bit), but after carefully reproducing the steps I took it still doesn't work.

I downloaded the SFML sources, ran cmake-gui and successfully configured the project to a second directory. Running make completes successfully, and all the files are successfully installed to /usr/local after calling make install.

On both my machines, I've set the environment variables:
LD_LIBRARY_PATH=/usr/local/lib
C_INCLUDE_PATH=/usr/local/include
CPLUS_INCLUDE_PATH=/usr/local/include

Just for testing purposes, I'm trying to build the example from http://www.sfml-dev.org/tutorials/2.1/start-linux.php

The command I'm using to build is:
g++ -O3 -Wall -Wextra -pedantic -std=c++11 -lsfml-graphics -lsfml-window -lsfml-system main.cpp
Even when I try adding the -L/usr/local flag, which shouldn't be necessary with my environment variables set, I still get SFML linker errors.

The following is the output I get, just for completeness' sake:

/tmp/cc9WdUuM.o: In function `main':
main.cpp:(.text.startup+0x5b): undefined reference to `sf::String::String(char const*, std::locale const&)'
main.cpp:(.text.startup+0x7f): undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
main.cpp:(.text.startup+0xba): undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
main.cpp:(.text.startup+0xee): undefined reference to `sf::CircleShape::CircleShape(float, unsigned int)'
main.cpp:(.text.startup+0xfa): undefined reference to `sf::Color::Green'
main.cpp:(.text.startup+0x102): undefined reference to `sf::Shape::setFillColor(sf::Color const&)'
main.cpp:(.text.startup+0x10c): undefined reference to `sf::Window::isOpen() const'
main.cpp:(.text.startup+0x130): undefined reference to `sf::Window::pollEvent(sf::Event&)'
main.cpp:(.text.startup+0x15c): undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
main.cpp:(.text.startup+0x16f): undefined reference to `sf::RenderTarget::clear(sf::Color const&)'
main.cpp:(.text.startup+0x186): undefined reference to `sf::RenderStates::Default'
main.cpp:(.text.startup+0x18e): undefined reference to `sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&)'
main.cpp:(.text.startup+0x196): undefined reference to `sf::Window::display()'
main.cpp:(.text.startup+0x1a4): undefined reference to `sf::Window::close()'
main.cpp:(.text.startup+0x1b8): undefined reference to `vtable for sf::CircleShape'
main.cpp:(.text.startup+0x1c0): undefined reference to `vtable for sf::CircleShape'
main.cpp:(.text.startup+0x1c5): undefined reference to `sf::Shape::~Shape()'
main.cpp:(.text.startup+0x1cd): undefined reference to `sf::RenderWindow::~RenderWindow()'
main.cpp:(.text.startup+0x207): undefined reference to `sf::RenderWindow::~RenderWindow()'
main.cpp:(.text.startup+0x220): undefined reference to `vtable for sf::CircleShape'
main.cpp:(.text.startup+0x228): undefined reference to `vtable for sf::CircleShape'
main.cpp:(.text.startup+0x22d): undefined reference to `sf::Shape::~Shape()'
collect2: error: ld returned 1 exit status


Maybe I'm just missing a crucial step, or I'm missing something that I'm unaware I should be doing to get it running in Ubuntu. Nevertheless, I would appreciate a fresh set of eyes looking at my situation, because I can't seem to get this working by myself. Thanks in advance

Pages: [1]
anything