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

Pages: [1]
1
Hi,
I am trying to implement 'dragging' the object on the screen.
My draw function looks like this:
    void GraphSprite::draw(sf::RenderWindow* win, vec2 offset)
    {      
        sf::Transform finalt = transform; // transform is a data member of my object
        finalt.translate(offset.x, offset.y);
        sf::RenderStates state(transform);
       
        win->draw(edgeArray.data(),edgeArray.size(), sf::Lines, state);
    }
 
And I handle the respective inputs in the following way:
    void GraphSprite::handleClick(float x,float y)
    {
//         std::cout <<"PRESSED: "<< x<<' '<< y<<std::endl;
        fixInput(x,y);
        if(x<=sizex && y<=sizey)
        {
            pressed=true; // this is made false when mouse is released
            initial = {x,y};
        }
    }
    void GraphSprite::handleMoved(float x, float y)
    {
//         std::cout <<"MOVED: "<< x<<' '<< y<<std::endl;
        fixInput(x,y);
        if (pressed == true && x<=sizex && x>=0 && y<=sizey && y>=0)
        {
            transform.translate(x - initial.x, y-initial.y);
            initial = {x,y};
        }
    }
 

This works fine, but the 'translation' take place in the wrong frame of reference.
(i.e when the renderstate has a rotation of 90 degrees, dragging horizontally moves the object vertically)

To fix this, I created the following function:
        void fixInput(float& x, float& y)
        {
            sf::Transform inv = transform.getInverse();
            auto result = inv.transformPoint(x,y);
            x = result.x;
            y = result.y;
        }
 
The result is that it seems very jerky when the dragging takes place (the axis issue is fixed though !)

I'll try to include a video/gif if anyone want a more visual description of the problem.

2
Graphics / Re: Can't put text on my OpenGL drawing.
« on: November 20, 2012, 09:01:21 am »
You should read the doc/examples/tutorials ;)
Hint: getDefaultFont() is a static function and it returns something.
Changed that part to:
sf::Font font(sf::Font::getDefaultFont());
 
Since, sf::Font has a copy constructor that should be alright, I guess.
And sf::Text default constructs itself with the default font anyway .
(and the docs are great, btw !)

And it doesn't seem to change anything visible, unfortunately.

3
Graphics / Can't put text on my OpenGL drawing.
« on: November 20, 2012, 08:49:47 am »
Here is what I'm doing:
(The OpenGl stuff isn't encapsulated yet, as I'm just learning it now)
What seems to be missing ?
Here is the main loop:
        while(win.isOpen())
        {              
                draw();        
                win.display();
               
                std::string input;
                std::getline(std::cin,input);
                std::cout<<shell(input);
               
                win.pushGLStates();
                        sf::Font font;
                        font.getDefaultFont();
                        sf::Text text;
                        text.setFont(font);
                        text.setCharacterSize(20);
                        text.setStyle(sf::Text::Bold);
                        text.setColor(sf::Color::Black);
                        text.setPosition(0,0);
                        text.setString(input);
                        win.draw(text);
                win.popGLStates();
               
               
                sf::Event eve;
                while(win.pollEvent(eve))
                {
                        if(eve.type==sf::Event::Closed)
                                win.close();
                }
        }
 

And the rest of the main.cpp file, (though everything other than the text gets drawn fine).
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Graphics/Text.hpp>
#include <GL/glew.h>
#include <iostream>
#include "shader.h"
#include "program.h"
#include "logostate.h"
#include "shell.h"
void setup();
void draw();

namespace global
{
        GLuint trail_vao,turtle_vao,trail_vbo,turtle_vbo;
        mm::Program* turtle_prog,*trail_prog;
        GLint col_ul,theta_ul;
        mm::LogoState turtle;
}
using namespace global;
void GlewInit()
{
        GLenum err = glewInit();
        if (GLEW_OK != err)
                std::cerr<<"Error "<<glewGetErrorString(err);
}

int main()
{
        sf::RenderWindow win(sf::VideoMode(600,600,32),"Logo");
        GlewInit();
        setup();
        mm::Shell shell(&turtle);
       
        while(win.isOpen())
        {              
                draw();        
                win.display();
               
                std::string input;
                std::getline(std::cin,input);
                std::cout<<shell(input);
               
                win.pushGLStates();
                        sf::Font font;
                        font.getDefaultFont();
                        sf::Text text;
                        text.setFont(font);
                        text.setCharacterSize(20);
                        text.setStyle(sf::Text::Bold);
                        text.setColor(sf::Color::Black);
                        text.setPosition(0,0);
                        text.setString(input);
                        win.draw(text);
                win.popGLStates();
               
               
                sf::Event eve;
                while(win.pollEvent(eve))
                {
                        if(eve.type==sf::Event::Closed)
                                win.close();
                }
        }
        return 0;
}

void setup()
{

        turtle_prog = new mm::Program
        (
                {
                        mm::Shader(GL_VERTEX_SHADER,"turtle.vert"),
                        mm::Shader(GL_FRAGMENT_SHADER,"turtle.frag")
                }
        );
        trail_prog = new mm::Program
        (
                {
                        mm::Shader(GL_VERTEX_SHADER,"trail.vert"),
                        mm::Shader(GL_FRAGMENT_SHADER,"trail.frag")
                }
        );
       
        glGenVertexArrays(1,&trail_vao);
        glBindVertexArray(trail_vao);
        glGenBuffers(1,&trail_vbo);
        glBindBuffer(GL_ARRAY_BUFFER,trail_vbo);
        glBufferData(GL_ARRAY_BUFFER,turtle.vdata.size()*sizeof(float),turtle.vdata.data(),GL_DYNAMIC_DRAW);
        glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,0,0);
        glEnableVertexAttribArray(0);
       
        glGenVertexArrays(1,&turtle_vao);
        glBindVertexArray(turtle_vao);
        glGenBuffers(1,&turtle_vbo);
        glBindBuffer(GL_ARRAY_BUFFER,turtle_vbo);
        glBufferData(GL_ARRAY_BUFFER,6*sizeof(float),turtle.turtle(),GL_DYNAMIC_DRAW);
        glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,0,0);
        glEnableVertexAttribArray(0);
}
void draw()
{
       
        float* x=turtle.bgColor();
        glClearColor(x[0],x[1],x[2],x[3]);
        glClear(GL_COLOR_BUFFER_BIT);
       
        glUseProgram(trail_prog->getHandle());
        float *y = turtle.penColor();
        col_ul = glGetUniformLocation(trail_prog->getHandle(),"col");
        glUniform4fv(col_ul,1,y);
       
        glBindVertexArray(trail_vao);
        glBindBuffer(GL_ARRAY_BUFFER,trail_vbo);
        glBufferData(GL_ARRAY_BUFFER,turtle.vdata.size()*sizeof(float),turtle.vdata.data(),GL_DYNAMIC_DRAW);
        glDrawArrays(GL_LINE_STRIP,0,turtle.vdata.size()/2);
       
        glUseProgram(0);
       
        glUseProgram(turtle_prog->getHandle());
        glBindVertexArray(turtle_vao);
        glBindBuffer(GL_ARRAY_BUFFER,turtle_vbo);
        glBufferData(GL_ARRAY_BUFFER,6*sizeof(float),turtle.turtle(),GL_DYNAMIC_DRAW);
        glDrawArrays(GL_TRIANGLES,0,3);
       
        glUseProgram(0);
       
}
 
The ultimate goal here is to get rid of iostream totally and get the input using sf::Event and mirrorring the input to the window in realtime. So, if there is a shortcut to that, please point me to that instead.

4
Window / Making a Sandbox for learning OpenGL
« on: September 03, 2011, 02:53:40 am »
Hello (...)
I decided to learn sfml and OpenGL together (instead of going with glut)
The OpenGL book I'm following shows how to use glut to set up things like double buffering. (How much it is handled automatically?)
I wrote the following program as a base on which I'd be applying everything I learn about OpenGL in near future. (changing the initialize() and draw()  when necessary.)
Could anyone of you review it to see if anything else is necessary ?
Code: [Select]

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

using namespace sf;

void draw(int x);
void initialize();

int main()
{
    Window app(VideoMode(320,240,32),"Manasij");
    app.UseVerticalSync(true);
    initialize();
    int x(0);
    bool running(1);
    while(running)
    {
        Event event;
        while(app.GetEvent(event))
        {
            if(event.Type == Event::Closed)
                running = false;
            if(event.Type == Event::KeyPressed && event.Key.Code == Key::P) //Pause
                std::cin.get();
        }
       
        draw(x++);
             
        app.Display();
    }
    return 0;
}

void draw(int x)
{
    glClear ( GL_COLOR_BUFFER_BIT );
    glBegin(GL_POLYGON);

    glVertex3i(40+x%100,200,0);
    glVertex3i(80,200,0);
    glVertex3i(80,100,0);
    glEnd();
   
    glFlush();
}

void initialize()
{
    glClearColor ( 1.0, 1.0,1.0, 0.0 );
    glColor3f(0.0f, 0.0f,0.0f);

    glPointSize(1.0);

    glMatrixMode ( GL_PROJECTION );
    glLoadIdentity();
    gluOrtho2D ( 0.0, (GLdouble)320, 0.0, (GLdouble)240 );
}


5
General / Just the Basics
« on: September 01, 2011, 02:13:03 am »
Quote
I would love to see a piece of code from start to finish that JUST opens up a window/screen and plots a single point to it, with the necessary settings commented so that I can at least have a definite place to start.


Then you'd 'love' to open the samples folder !

6
General discussions / Compiling the source on Fedora 15
« on: September 01, 2011, 01:09:50 am »
Quote from: "OniLink10"
Add that include to SFML/System/ResourcePtr.inl.


There isn't such a file in the source, or I'd have done that.

7
General discussions / Compiling the source on Fedora 15
« on: September 01, 2011, 12:10:18 am »
I apologize if this isn't the right place to post this. Kindly point me to it if it isn't.

I tried to compile the source because the binary installation could not find the shared library during runtime.
The error was:
Code: [Select]
./a: error while loading shared libraries: libsfml-system.so.1.6: cannot open shared object file: No such file or directory

So, I tried to compile(gcc-4.6 on Fedora 15) and got the following error message:

Code: [Select]
../../../include/SFML/System/ResourcePtr.inl: In constructor ‘sf::ResourcePtr< <template-parameter-1-1> >::ResourcePtr()’:
../../../include/SFML/System/ResourcePtr.inl:31:12: error: ‘NULL’ was not declared in this scope
../../../include/SFML/System/ResourcePtr.inl: In member function ‘void sf::ResourcePtr< <template-parameter-1-1> >::OnResourceDestroyed()’:
../../../include/SFML/System/ResourcePtr.inl:148:18: error: ‘NULL’ was not declared in this scope


Seeing NULL not declared, I added a
#include<cstddef>
in the initializer file in System/Unix/ and some other files alternatively.
<The files mentioned in the error are probably generated when make is running>
...but that did not solve the problem.

Any idea what to do ?

Pages: [1]
anything