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

Pages: [1] 2
1
Graphics / Re: Transparent part of a sprite
« on: July 31, 2015, 02:00:57 pm »
Hey what your talking about is pixel perfect collision, the intersects function that SFML has built in would act at bounding box collision. I believe that SFML doesn't have pixel perfect collision built into it, I think I remember reading something similar to this before.

Hmm you probably could code it yourself, you have access to all the pixels of your sprite, I'm not sure how efficient it would be but could be a fun project for you I'm sure, teach you a lot more about the basics of collision detection.

2
Graphics / Re: [Solved] Fade effect
« on: July 31, 2015, 01:55:52 pm »
Hey I know this is solved but I thought I might share a little more knowledge. If you use linear interpolation you should get a more manageable effect:

        int startAlpha = 0;
        int endAlpha = 255;
        int targetTime = 1000;
        sf::Clock timer;

        int currentTime = timer.getElapsedTime().asMilliseconds();
        int currentAlpha = endAlpha;
        if (currentTime >= targetTime)
        {
                //you are done
        }
        else
        {
                currentAlpha = startAlpha + (endAlpha - startAlpha)*currentTime / targetTime;
        }
        fade.setFillColor(Color(0, 0, 0, currentAlpha));
 

3
Thanks for the suggestions, I actually fixed this maybe 2 days ago, the solution was to add the code:
window.setActive();
 

Just after loading the texture.

4
Thanks for that I looked into and changed to the fallowing code:
glTranslatef(0.f, 0.f, -5.f);

...

glNormal3f(0.0f, 0.0f, 1.0f);
glColor3f(1.0f, 0.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f);      glVertex3f(-1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f);      glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f);      glVertex3f(1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f);      glVertex3f(1.0f, 1.0f, 1.0f);
 

I like 1's better than 50's... So still the same problem whole screen goes black, still not sure, any more suggestions?

5
Hey everyone, I need to create some perspective, I tried convex shapes, vertex arrays and shaders... no avail, that is why I found myself looking at raw openGL.

I'm pretty well versed in DirectX but this is the first time I've looked into openGL, so far so good and I have created the perspective without problems. However I'm not trying to texture my square, this will probably be a simple fix but I have no idea so please help me.

#include "stdafx.h"
#include <iostream>
#pragma comment(lib,"opengl32.lib")
#pragma comment(lib,"glu32.lib")
#include <SFML/Graphics.hpp>
#include <gl/GLU.h>

int main()
{
        // Create window
        sf::RenderWindow window(sf::VideoMode(0,0,1024, 768), "SFML Perspective");

        //load the texture
        sf::Texture texture;
        if (!texture.loadFromFile("images\\images.png"))
        {
                return EXIT_SUCCESS;
        }
        texture.setRepeated(true);

        //initialise OPENGL
        glClearDepth(1.0f);
        glClearColor(1.f, 1.0f, 1.0f, 0.0f);
        glEnable(GL_DEPTH_TEST);
        glDepthMask(GL_TRUE);

        //// Setup the camera
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(90.0f, 1.0f, 1.0f, 500.0f);

        // Game loop
        while (window.isOpen())
        {
                // Process events
                sf::Event Event;
                while (window.pollEvent(Event))
                {
                        if (Event.type == sf::Event::Closed)
                        {
                                window.close();
                        }
                }

                // Clear the screen
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

                // Preform the appropriate transformations
                glMatrixMode(GL_MODELVIEW);
                glLoadIdentity();
                glTranslatef(0.f, 0.f, -150.f);

                glRotatef(30.0f, 0.f, 1.f, 0.f);

                glEnable(GL_TEXTURE_2D);
                sf::Texture::bind(&texture);
                //Draw a face
                glBegin(GL_QUADS);
                {
                        glColor3f(0, 0, 1);
                        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();
                sf::Texture::bind(NULL);

                window.display();
        }
        return EXIT_SUCCESS;
}
 

That is my code nice and simple.
When I comment out all of the code to do with texturing namely:
sf::Texture texture;
if (!texture.loadFromFile("images\\images.png"))
{
        return EXIT_SUCCESS;
}
texture.setRepeated(true);

...

glEnable(GL_TEXTURE_2D);
sf::Texture::bind(&texture);

...

sf::Texture::bind(NULL);
 

It works fine and I get (see attachment). When I put the lines of code back in I just get a black screen... what am I doing wrong, any help would be appreciated.

6
General / Re: GetDC() NULL
« on: September 18, 2014, 10:52:35 am »
OK thanks, that's all I needed to know. If there isn't already maybe a small message in the render texture documentation should mention that a limited amount can be created depending on system resources.

The system is not something i have written on my own it's a team of people that have been working on it for about 3-4 years and this functionality has been in it from the start it's only becoming a problem now due to the complexity of the games we are making. This is a system that cannot be changed at such a fundamental part so we will need to think up a good solution for this.

Thanks for your help everyone.

7
General / Re: GetDC() NULL
« on: September 18, 2014, 10:36:35 am »
As much as this may be a good solution it's not really very suitable for my needs, it would require quite a lot of change, is there nothing else that can be drawn to?

8
General / Re: GetDC() NULL
« on: September 18, 2014, 10:26:48 am »
Interesting, well if render textures are not the most appropriate thing to use then what should be used instead? I require something that I can draw to, then draw that to a window with a lot of other sprites.

The act of creating 200 was only to guarantee the problem happening every time, I actually only use around 18-36 depending on the game, and the problem is intermittent some times it does break some times it doesn't.

9
General / Re: GetDC() NULL
« on: September 17, 2014, 12:59:47 pm »
Yeah it's not the best coding example I don't usually use new without deleting them later, or global points, I'm not a dumbass however this still points out the problem. The GPU has 2GB of memory, take out the 315MB that windows uses leaves over 1750~mb of free GPU memory. Opening up a graphics monitor shows that the card only uses around 635mb.

AlexAUT your calculation is correct.

Yes I do need that many render textures.

10
General / GetDC() NULL
« on: September 17, 2014, 12:21:14 pm »
I have made a game that requires lots of render textures to be created, my game seems to break when a function in WglContext.cpp (the constructor) is called, this function is called GetDC() it returns me NULL. After doing some research on the interwebs MSDN says "If the function fails, the return value is NULL." and "The number of DCs is limited only by available memory." My system has 16 GB of ram and it's not even coming close to this.

I have created a program to simulate this issue:

#include <iostream>
#include <vector>
#include "SFML\Window.hpp"
#include "SFML\Graphics.hpp"

using namespace std;

void render();
sf::Texture* text;
sf::Sprite sprt;
vector<sf::Sprite*> windowSprites;
vector<sf::RenderTexture*> rndText;
sf::RenderWindow* window;

int main()
{
        text = new sf::Texture();
        text->loadFromFile("image.png");
        sprt.setTexture((*text));
        window = new sf::RenderWindow(sf::VideoMode(0,0,900,527),"Window");

        for(int i = 0; i < 200; i++)
        {
                rndText.push_back(new sf::RenderTexture());
                rndText[i]->create(900,527);
                windowSprites.push_back(new sf::Sprite());
                windowSprites[i]->setTexture(rndText[i]->getTexture());
                cout << i << endl;
                render();
        }
        while(true)
        {
                render();
        }
        return 0;
}

void render()
{
        window->clear();
        for(int i = 0; i < rndText.size(); i++)
        {
                rndText[i]->clear();
                rndText[i]->draw(sprt);
                rndText[i]->display();
                window->draw((*windowSprites[i]));
        }
        window->display();
}
 

It seems to be pretty random when GetDC() returns NULL, can anyone shed any light on this?!

Thanks Guys!

11
Graphics / Re: Shaders and texture rects
« on: September 17, 2014, 12:13:36 pm »
How right you are, thanks!

12
Graphics / Re: Shaders and texture rects
« on: July 15, 2014, 04:32:32 pm »
That worked perfectly thank you very much!!

Just so everyone can see this is the new shader:

uniform sampler2D texture;
uniform float time;
uniform float waveWidth;
uniform float amplitude;
uniform float speed;
void main()
{
   vec2 colour = gl_TexCoord[0].xy;

   colour.y += sin(colour.x*waveWidth+(time/speed))/amplitude;

   gl_FragColor = texture2D(texture,colour);
}

13
Graphics / Re: Shaders and texture rects
« on: July 15, 2014, 04:28:08 pm »
Thank's for the help, so you are saying if I were to use gl_TexCoord[0] instead I would have better results?

14
Graphics / Re: Scale creating lines around sprites
« on: July 15, 2014, 04:04:01 pm »
Well I fixed this by turn off texture smoothing on all the textures, doing all transformations on the sprites, drawing them to a single rendertexture that is set smooth and then drawing that to the window.

Thanks for your help guys! :D

15
Graphics / Shaders and texture rects
« on: July 15, 2014, 03:59:18 pm »
Hey guys,

So I have this problem:

I have a texture that is let's say 1024x1024.
I have a sprite with a subrect of 100,200,500x500.
I have a wave fragment shader that is this:

uniform sampler2D texture;                       //sf::Shader::CurrentTexture
uniform vec3 iResolution;                          //1000,800,1
uniform float time;                                    //A Clock returning miliseconds
uniform float waveWidth;                         //50
uniform float amplitude;                           //150
uniform float speed;                                //100
void main()
{
   vec2 colour = gl_FragCoord.xy / iResolution.xy;

   colour.y = 1.0 - colour.y;

   colour.y += sin(colour.x*waveWidth+(time/speed))/amplitude;

   gl_FragColor = texture2D(texture,colour);
}

The problem is that the whole texture not just the subrect is being scaled to the size of the window and having the wave effect.

I have tried adding this code:

glViewport(100,200,500,500);

But this didn't work.

Anyone have any ideas of how I could maintain the subrect of the sprite?

Thanks everyone!

Pages: [1] 2
anything