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

Pages: [1]
1
Graphics / Starting With OpenGL
« on: January 06, 2014, 12:00:42 am »
I am attempting to run the first example on the openGL tutorial.

http://sfml-dev.org/tutorials/2.1/window-opengl.php

I receive errors as follows:

Quote
1>main.obj : error LNK2019: unresolved external symbol __imp__glClear@4 referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol __imp__glViewport@16 referenced in function _main

I believe there is a file named opengl32.lib that I have to do something with. Some of the guides tell me the location, so maybe I need to copy it to my project? Some tell me things about other libraries like glu and ones I obviously don't need like glut. And finally there are a few tutorials telling me that I can put a linker option (which I assume goes in Linker command line options). Nothing I try is working and I'm getting very frustrating and I have over a hundred tabs of tutorials I've tried and I don't know why this is so complicated.

I am using Microsoft Visual C++ 2010.

2
Graphics / Re: Creating Large Number Of Stars Efficiently
« on: January 05, 2014, 10:43:49 pm »
Thanks for your help with that error.

At the moment, the blur shader doesn't appear to be having any effect. I know it is loading because the whole screen turned purple when I tested.

However, when I restore it to the normal shader code, the screen appears unchanged.

uniform sampler2D texture;
uniform float blur_radius;

void main()
{
    vec2 offx = vec2(blur_radius, 0.0);
    vec2 offy = vec2(0.0, blur_radius);

    vec4 pixel = texture2D(texture, gl_TexCoord[0].xy) * 4.0 +
                 texture2D(texture, gl_TexCoord[0].xy - offx) * 2.0 +
                 texture2D(texture, gl_TexCoord[0].xy + offx) * 2.0 +
                 texture2D(texture, gl_TexCoord[0].xy - offy) * 2.0 +
                 texture2D(texture, gl_TexCoord[0].xy + offy) * 2.0 +
                 texture2D(texture, gl_TexCoord[0].xy - offx - offy) * 1.0 +
                 texture2D(texture, gl_TexCoord[0].xy - offx + offy) * 1.0 +
                 texture2D(texture, gl_TexCoord[0].xy + offx - offy) * 1.0 +
                 texture2D(texture, gl_TexCoord[0].xy + offx + offy) * 1.0;

    gl_FragColor = gl_Color * (pixel / 16.0);
}

I tried manually filling in the blur_radius, in case I had to fill that in. I tried both 4.0 and 1.0. I notice no difference to the screen except strange random horizontal and vertical lines all the way across the screen, the same colour as some of the stars.

I also tried to change the code a bit like this to see if that would do anything:

  vec4 pixel = texture2D(texture, gl_TexCoord[0].xy) * 0.0 +
               texture2D(texture, gl_TexCoord[0].xy - offx) * 2.5 +
               texture2D(texture, gl_TexCoord[0].xy + offx) * 2.5 +
               texture2D(texture, gl_TexCoord[0].xy - offy) * 2.5 +
               texture2D(texture, gl_TexCoord[0].xy + offy) * 2.5 +
               texture2D(texture, gl_TexCoord[0].xy - offx - offy) * 1.5 +
               texture2D(texture, gl_TexCoord[0].xy - offx + offy) * 1.5 +
               texture2D(texture, gl_TexCoord[0].xy + offx - offy) * 1.5 +
               texture2D(texture, gl_TexCoord[0].xy + offx + offy) * 1.5;

Here is the code:

        sf::Shader blur;
        if (sf::Shader::isAvailable())
        {
                if (!blur.loadFromFile("blur.frag", sf::Shader::Fragment))
                {
                        std::cout << "Could Not Load Blur Shader!" <<std::endl;
                }
        }
        else
        {
                std::cout << "Error! Shaders Not Supported!" <<std::endl;
        }
        sf::RenderTexture blurtexture;
        if (!blurtexture.create(sf::VideoMode::getDesktopMode().width, sf::VideoMode::getDesktopMode().height))
        {
                std::cout << "Error Creating BlurTexture!" << std::endl;
        }

                blurtexture.clear(sf::Color::Black);
                blurtexture.draw(smallstars);
                for (i = 0; i < LARGESTAR_COUNT; i ++) {
                        blurtexture.draw(largestars[i]);
                }
                blurtexture.display();
                sf::Sprite blursprite(blurtexture.getTexture());

        window.clear(sf::Color::Black);
        window.draw(blursprite, &blur);
        window.display();

3
Graphics / Build a Realistic Sphere
« on: January 05, 2014, 07:44:48 pm »
I am currently able to build nice beautiful circles like this:

void resetPlanetVertexes (sf::VertexArray* planet, sf::Vector2f* center, float size, sf::Color* color)
{
        int i;
        int count = (int)(planet->getVertexCount());
        for (i = 1; i < count-1; i ++) {
                float angle = ((float)(i) / (float)(count-2) * 360.f) * 3.14f / 180.f;
                ((*planet)[i]).position = *center + sf::Vector2f(
                        (float)(std::cos(angle) * size),
                        (float)(std::sin(angle) * size)
                );
                ((*planet)[i]).color = *color;
        }
        ((*planet)[count-1]).position = ((*planet)[1]).position;
        ((*planet)[count-1]).color = ((*planet)[1]).color;
}

void buildPlanet (sf::VertexArray* planet, sf::RenderWindow* window)
{
        int width = (int)(window->getSize().x);
        int height = (int)(window->getSize().y);
        sf::Color planetcolor = getPlanetColor();
        float size = getPlanetSize();
        std::cout << "Planet Size: " << size << std::endl;
        sf::Vertex* planetcenter = &((*planet)[0]);
        planetcenter->position = sf::Vector2f
                                ((float)(rand() % (width + (PLANET_BORDER<<1)))-PLANET_BORDER,
                                (float)(rand() % (height + (PLANET_BORDER<<1)))-PLANET_BORDER);
        planetcenter->color = planetcolor;
        resetPlanetVertexes(planet, &(planetcenter->position), size, &(planetcenter->color));
}

However, they look obviously flat and not like planets at all. They look like someone cut perfect circles out of construction paper.



If we look at a planet like Neptune, we see that the bottom right fades towards black, while the top left fades towards a slightly brighter color to create the appearance of a sphere and not a circle.

I think I can probably do something with the coloring to darken or lighten it. (Not sure the best way to do that.) Do I really have to modify each of the three rgb values to lighten/darken a colour?

I also thought there might be a way to build a 3D planet or something similar to that as well.

I want to make each planet random and different so I don't want to use a standard sprite.

4
Graphics / Re: Creating Large Number Of Stars Efficiently
« on: January 05, 2014, 03:30:31 am »
I'm doing another attempt, this time using the sf::TrianglesFan to create gradient triangles in a circle around the central star. Here's the code:

        sf::VertexArray examplestar(sf::TrianglesFan, 8);
        buildStarExample(&examplestar, &window);

void buildStarExample (sf::VertexArray* star, sf::RenderWindow* window)
{
        int width = (int)(window->getSize().x);
        int height = (int)(window->getSize().y);
        float size = 30.f;

        sf::Vector2f center = sf::Vector2f
                                ((float)(rand() % width),
                                (float)(rand() % height));
        ((*star)[0]).position = center;
        std::cout << center.x << " - " << center.y << std::endl;
        ((*star)[0]).color = sf::Color((rand()%64)+192, (rand()%64)+192, rand()%256, 255);

        unsigned int i;
        for (i = 0; i < star->getVertexCount(); i ++) {
                float angle = ((float)(i) / (float)(star->getVertexCount()) * 360.f) * 3.14f / 180.f;
                ((*star)[i]).position = center + sf::Vector2f(
                        (float)(std::cos(angle) * size),
                        (float)(std::sin(angle) * size)
                );
                ((*star)[i]).color = ((*star)[0]).color;
                //((*star)[i]).color.a = 0;
        }
}

At the moment, it's a solid octagon shape. The moment I uncomment the line '((*star)).color.a = 0;', the whole star disappears. I expect the center to be solid, and the edges transparent. Why is it not fading to transparent?

5
Graphics / Re: Failing To Load Font
« on: January 05, 2014, 02:34:27 am »
Thanks For Your Help!

I now have a beautiful text title!


On this page here:
http://www.sfml-dev.org/tutorials/2.0/start-vc.php

I would suggest to also highlight in red the 'Configuration: Release' as it comes up by default in Debug. Or, set the files to -d instead.


And perhaps the note from below that table can be included in the text and fonts tutorial, to be extra safe.

6
Graphics / Re: Creating Large Number Of Stars Efficiently
« on: January 05, 2014, 02:15:45 am »
Okay I've made 30,000 beautiful pixelated stars using a VertexArray.

I'd now like to make them not pixelated, and more like shining stars.

I tried to apply a blur shader which Laurent made here:
https://github.com/SFML/SFML/blob/master/examples/shader/resources/blur.frag

However it seems to make the stars invisible. I modified the last line to 'gl_FragColor = gl_Color' and everything showed up okay.

Next, I did a simple test to make each pixel purple. 'gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);'

So, it seems that I can only control the single individual pixel, and in order to make the stars more realistic, I obviously would have to brighten the surrounding pixels somewhat. Is this possible with shaders and how would I go about doing it?

7
Graphics / Re: Failing To Load Font
« on: January 04, 2014, 12:25:35 am »
By debug-mode, do you mean this:



And by release libs, are they under linker > additional dependencies?



I tried to change each name to add a -d for debug, but the error persists. I am now trying from scratch with the arial font from Windows/fonts.

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

int main () {

        sf::Font font;
        if (!font.loadFromFile("arial.ttf"))
        {
                std::cout << "Load Failed!" <<std::endl;
                return 0;
        }

        sf::RenderWindow window(sf::VideoMode(200, 200), "SFML Text Test!");
        sf::Text text;

        // select the font
        text.setFont(font); // font is a sf::Font

        // set the string to display
        text.setString("Hello world");

        // set the character size
        text.setCharacterSize(24); // in pixels, not points!

        // set the color
        text.setColor(sf::Color::Red);

        // set the text style
        text.setStyle(sf::Text::Bold | sf::Text::Underlined);

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

        window.clear();
        window.draw(text);
        window.display();
    }

    return 0;
}

It runs into that error before even going into the failure code.

8
Graphics / Re: Creating Large Number Of Stars Efficiently
« on: January 03, 2014, 11:38:26 pm »
I thought that this may be faster.

It still takes about a second to load the texture now with just 2500 stars in 1000x1000. I'm wondering if there is a faster way to set pixels...

void buildStarTexture (sf::RenderTexture* texture)
{
        sf::CircleShape star(1, 4);
        int i;
       
        if (!texture->create(STAR_TEXTURE_WIDTH, STAR_TEXTURE_HEIGHT))
        {
                // error...
        }
        texture->clear();
        star.setFillColor(sf::Color::Yellow);
        for (i = 0; i < STAR_TEXTURE_YELLOW; i ++) {
                star.setPosition(rand() % STAR_TEXTURE_WIDTH, rand() % STAR_TEXTURE_HEIGHT);
                texture->draw(star);
        }
        star.setFillColor(sf::Color::White);
        for (i = 0; i < STAR_TEXTURE_WHITE; i ++) {
                star.setPosition(rand() % STAR_TEXTURE_WIDTH, rand() % STAR_TEXTURE_HEIGHT);
                texture->draw(star);
        }
        texture->display();
}

9
SFML website / Think This Is A Typo
« on: January 03, 2014, 11:28:06 pm »
On this page:
http://www.sfml-dev.org/tutorials/2.0/graphics-draw.php

You have this text in the Off-screen drawing section:
sf::Texture& texture = renderTexture.getTexture();

// draw it to the window
sf::Sprite sprite(texture);

I think the ampersand is a typo.

10
Graphics / Failing To Load Font
« on: January 03, 2014, 10:52:12 pm »
My program:

int main()
{
        sf::Font font;
        if (!font.loadFromFile("Xolonium-Regular.otf"))
        {
                // error...
        }
    sf::RenderWindow window(sf::VideoMode::getDesktopMode(), "SFML works!", sf::Style::Fullscreen);
        window.setVerticalSyncEnabled(true);

        sf::Text title;
        title.setFont(font); // font is a sf::Font
        title.setString("Hello World!");
        title.setCharacterSize(64); // in pixels, not points!
        title.setColor(sf::Color::White);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
                        switch (event.type)
                        {
                                case sf::Event::KeyPressed: //Key pressed
                                        switch (event.key.code)
                                        {
                                        case sf::Keyboard::Escape:
                                                window.close();
                                                break;
                                        }
                                        break;
                        }
        }

        // clear the window with black color
        window.clear(sf::Color::Black);
               
        window.draw(title);
        window.display();
    }

    return 0;
}

Displays this weird text in the command prompt:



And displays this dialog:



According to this thread, OTF format should be supported:
http://en.sfml-dev.org/forums/index.php?topic=72.0

When I open the font it works fine to view in Windows. It's a font that's available on this site here:
http://www.fontspace.com/severin-meyer/xolonium

The font is in the same directory as sfml-graphics-2.dll and others... which I assume is the correct directory. It seems awfully strange if this is simply failing to find the file.

11
Graphics / Creating Large Number Of Stars Efficiently
« on: January 03, 2014, 10:15:23 pm »
I'm hoping to create a background which is randomized with lots of stars for a space-themed game. The stars all move in the same direction at the same time to simulate motion. There will be a lot of them, and I'd really like to create an efficient system.

I want it randomized, so it's not the same graphic over and over. What is the most efficient way to do this?

Do I want to create an array of star objects, similar to this code which doesn't work:

Quote
sf::CircleShape stars[] = sf::CircleShape[500];

Or is it recommended to do something more fancy, such as creating a random Image on the fly which is then moved in one piece?

Pages: [1]