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.


Topics - Synyster_Coder

Pages: [1]
1
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.

2
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!

3
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!

4
Graphics / Scale creating lines around sprites
« on: September 26, 2013, 01:24:17 pm »
Hi everyone,

I have had a problem with scaling sprites for a while now which is, when you scale a sprite above 1.0f the sprite will get a few extra pixels around it from the image tile that it came from. I have fixed this before by just adding a few extra pixels around the sprite on the tile that are alpha a "padding" if you will, but this just seems like a lot more hassle than just trying to fix the problem at the root.

I have been looking through the SFML Texture.cpp and found the functions setSmooth() and create() which calls the opengl function glTexParameteri, after looking online people are saying that if you use GL_CLAMP_TO_EDGE in the parameters for this instead of GL_NEAREST this could fix the problem.

So what I'm asking is will this fix the problem? May there by any implication from using this? And if not how come this isn't the default?

Thanks for the thoughts :D

5
General / Connecting lines (Vertex Arrays)
« on: June 04, 2013, 11:28:50 pm »
So I have this problem about drawing lines. Basically what I need is to draw a series of lines of equal thickness all connected to each other from where the last left off. Each line will end at a specific point then the next will be drawn to another point, very similar to a line graph, just with thicker lines.

I have got all the lines to connect no problem however I have found that the thickness of the line does not stay the same when the line is at an extreme angle, I have included a screen shot to show what I'm talking about. I'm pretty sure that i just have to position the vertices dependent of the angle but my trigonometry is really bad, can anyone give me a helping hand please, I would be really grateful?

[attachment deleted by admin]

Pages: [1]
anything