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 - Cuban-Pete

Pages: 1 2 [3] 4 5
31
SFML wiki / Added page about setIcon and make your own
« on: June 29, 2011, 12:32:28 pm »
Quote
I tried disabling one, that did not have any effect. I made copy of the function (every where it is used also virtual). One with the same name and one with Large after the name. I called them both in my program, but it has no effect. Also, the program got very unresponsive on the taskbar, very weird.

This also brings me to a different problem. With the basic sfml 2.0 code (so no adjustments) the time it takes after starting the program and showing up on the windows 7 taskbar is sometimes longer than 3 seconds. The program is started, I see the window, but it takes pretty long before it displays itself on the taskbar. How is this possible? On my vista PC it shows up directly on the taskbar.


Nobody has this long wait time before the program shows on the taskbar? Or am I the only one with win7 (64bit)?

32
Graphics / How do I display a variable?
« on: June 28, 2011, 09:44:32 pm »
hehe, misunderstanding. I was aiming at this part:

Quote from: "Nexus"

Usage:
Code: [Select]
int main()
{
    int health = 100;
    sf::String str(MakeString() << "Health: " << health);
}


there I use string() instead of str()

Sorry for wasting time...

33
Graphics / How do I display a variable?
« on: June 28, 2011, 09:29:08 pm »
Yes works for me, but you guys were wondering why it only worked with string() and not str().

34
Graphics / How do I display a variable?
« on: June 28, 2011, 09:23:08 pm »
The smallest and worst code where it still works... :P

Code: [Select]

#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>
#include <string>
#include <iostream>
#include <sstream>

using namespace std;

class MakeString  
{
   public:
      template <typename T>
      MakeString& operator<< (const T& value)
      {
         mStream << value;
         return *this;
      }
       
      operator std::string() const
      {
         return mStream.str();
      }
       
   private:
      std::ostringstream mStream;
};


int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "test", sf::Style::Close);

window.SetFramerateLimit(60);

   while (window.IsOpened())
{
        // Process events
        sf::Event event;
        while (window.PollEvent(event))
        {
            // Close window : exit
            if (event.Type == sf::Event::Closed)
                window.Close();

            // Escape key : exit
            if ((event.Type == sf::Event::KeyPressed) && (event.Key.Code == sf::Key::Escape))
                window.Close();
        }

sf::Text text( string(MakeString() << window.GetInput().GetMouseX() << " " << window.GetInput().GetMouseY() ) );
text.SetPosition(250.f, 450.f);
text.SetColor(sf::Color(255, 255, 255, 170));
window.Draw(text);

window.Display();
    }

    return 0; //EXIT_SUCCESS
}

35
Graphics / How do I display a variable?
« on: June 28, 2011, 09:03:24 pm »
I get this error:

Quote from: "VS2008"
error C3861: 'str': identifier not found


I have to use this also to make it work:
Quote

#include <string>
#include <iostream>
#include <sstream>
using namespace std;


Which suggests that I'm using std::string() instead of str().

36
Graphics / How do I display a variable?
« on: June 28, 2011, 08:01:22 pm »
Ahh, that works gorgeous. Small crit on your code in the other post. For me it only worked when changing str() to string().  :)

37
Graphics / How do I display a variable?
« on: June 28, 2011, 07:28:36 pm »
Thanks. That is a lot cleaner.

Is it wise to make a global ostringstream and use it multiple times? I guess I also need to clear it after each use.

Or would a function be better. How would I make such a function, the identifier can be int/char or whatever floats.

38
Feature requests / [Not needed] sf::Image Append
« on: June 28, 2011, 07:00:31 pm »
Awesome! That sf::Image::Copy() works like charm!  Thanks :D

39
Graphics / How do I display a variable?
« on: June 28, 2011, 06:51:26 pm »
Something like this?

Code: [Select]

#include <sstream>
#include <string>

...
string hello;

stringstream ss (stringstream::in | stringstream::out);
ss << window.GetInput().GetMouseX();
ss << " ";
ss << window.GetInput().GetMouseY();

hello = ss.str();

sf::Text text(hello);
text.SetPosition(250.f, 450.f);
text.SetColor(sf::Color(255, 255, 255, 170));
window.Draw(text);
...

40
Feature requests / [Not needed] sf::Image Append
« on: June 28, 2011, 06:32:54 pm »
I would like to see an image operator that appends images together.

I tried myself this and it's pretty difficult. Well, appending vertically (same width images) is not a problem, but horizontal it is.

If it is not on the agenda, I might try to create my own - if you guys want to help that is.  :roll:   :)  Perhaps I will start with a AppendVertical function.  :P

41
SFML wiki / Added page about setIcon and make your own
« on: June 28, 2011, 06:25:56 pm »
Quote from: "Cuban-Pete"
Can I adjust the sfml code so that just for windows I can add another icon without breaking the sfml code when compiling on other operating system. Something with #Ifset windows ?


I tried that, but it does not work.

These lines are important I think:
Code: [Select]

        SendMessage(myHandle, WM_SETICON, ICON_BIG,   (LPARAM)myIcon);
        SendMessage(myHandle, WM_SETICON, ICON_SMALL, (LPARAM)myIcon);


I tried disabling one, that did not have any effect. I made copy of the function (every where it is used also virtual). One with the same name and one with Large after the name. I called them both in my program, but it has no effect. Also, the program got very unresponsive on the taskbar, very weird.

This also brings me to a different problem. With the basic sfml 2.0 code (so no adjustments) the time it takes after starting the program and showing up on the windows 7 taskbar is sometimes longer than 3 seconds. The program is started, I see the window, but it takes pretty long before it displays itself on the taskbar. How is this possible? On my vista PC it shows up directly on the taskbar.

42
Graphics / [Solved] How to : Flash light
« on: June 27, 2011, 07:28:38 pm »
You could flash the whole screen with a white image. ...but people might get an hearth attack because of it. What you could also do is shake the camera a little.  :)

43
SFML wiki / Added page about setIcon and make your own
« on: June 27, 2011, 01:40:21 pm »
lol, all this trouble, while it was just converting to octal. of course, now that I know it, it makes sense.

For those that want to convert their image to a const unsigned char, like gimp does it. Here is my python code (it uses PIL).

Code: [Select]
"""
Cuban-Pete 2011

- free as beer code snippet
- this code snippet creates from images in the "images" folder one images.c file
- the created file can be loaded in your C(++) program.
- so colors go from decimal to octal format

"""

import os, sys, Image

lol = ''
f = open('images.c', 'w') #global set file. overwriting is 'on'

def run_colors_and_print(image_location, image_name ):
    image = Image.open(image_location) #open image
    pix = image.load() #put info in pix
    width = image.size[0]
    height = image.size[1]
    lol = '' #reset global! string, important
    ten_count = 0
    startbool = True #remove unneeded extra double quotes at start
   
    for y in range(0,height):
        for x in range(0,width):

            if ten_count == 0:
                if startbool == True:
                    lol = lol + "\n\t\""
                    startbool = False
                else:
                    lol = lol + "\"\n\t\""

            # putting in the RGBA.
            temp = "\%o\%o\%o\%o" % (pix[x,y][0], pix[x,y][1], pix[x,y][2], pix[x,y][-1]);
            lol = lol + temp
           
            ten_count += 1
            if ten_count == 10: #make lines as long as this value...
                ten_count = 0
           
    f.write("static const struct {")
    f.write("\n\t unsigned int \t width;")
    f.write("\n\t unsigned int \t height;")
    f.write("\n\t unsigned int \t bytes_per_pixel;")
    f.write("\n\t unsigned char \t pixel_data[%i * %i * 4 + 1];" % (width, height) )
    #the image name is made here (currently set on "normal_" and followed by image file name
    f.write("\n} normal_%s = {" % (image_name[ 0: len(image_name)-4 ]) ) #remove the ".png" tag and backslash
    f.write("\n\t%i, %i, 4," % (width, height) )
    f.write("%s\"," % (lol) ) #the pixel data written
    f.write("\n};")

    print "done %s" % (image_name)
   

## loop in the "images" folder to get all images
image_folder = "images/"
for subdir, dirs, files in os.walk(image_folder):
    for file in files:
        run_colors_and_print(image_folder+file, file)
        f.write("\n\n")


f.close() #important!


##Ouput example below for a 2x2 image in all white:
   
##static const struct {
##  unsigned int width;
##  unsigned int height;
##  unsigned int bytes_per_pixel;
##  unsigned char pixel_data[2 * 2 * 4 + 1];
##} gimp_image = {
##  2, 2, 4,
##  "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377",
##};



44
SFML wiki / Added page about setIcon and make your own
« on: June 26, 2011, 11:15:14 pm »
I got a question about converting an image to a c-source file. Now I just let GIMP do it, but because I want more images to be converted I want to automate it. However I can't figure out how to convert the RGBA value to a unsigned char (in an array) that the compiler accepts.

This is what I figured out by trying. Color value from 0 up to and including 32 are represented with "/number". So for example the color 0 is "/0" or blue color 7 is "/7". But than comes the problem, all the decimal numbers with an 8 or 9 in it are skipped. I think this is because of 8 bit. 0 up to and including 7 makes in total -> 8. Than from 33 up and including 126 is represented with just the ASCII character. So for example the color value 126 is represented as "~", the wave thingy. :) From 127 and up it's again with "/number" and 8 and 9's are avoided.

Now the problem is, how to convert the 0-255 color value to this unsigned char value. I prefer to do this with Python, codes quick for getting such stuff.

Here is an example c code from an image with only 2 pixels. First black (0), second is white (255).

Quote
static const struct {
  unsigned int     width;
  unsigned int     height;
  unsigned int     bytes_per_pixel; /* 3:RGB, 4:RGBA */
  unsigned char    pixel_data[1 * 2 * 4 + 1];
} gimp_image = {
  1, 2, 4,
  "\0\0\0\377\377\377\377\377",
};



The \0 is just zero (black) and the \377 is 255 (white).

45
Graphics / Shader not working on "newer" machines
« on: June 26, 2011, 09:52:05 pm »
I'm no expert, but I think you need to define the version you are using.

Put this "#version 120" above the shader code.

I got it from here: http://en.wikipedia.org/wiki/GLSL

Pages: 1 2 [3] 4 5
anything