16
Graphics / sf::Image::LoadFromPixels Size Limit
« on: October 23, 2010, 07:30:29 am »
Is there a size limit for images loaded with sf::Image::LoadFromPixels?
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.
// Resize event
case WM_SIZE :
{
// Update window size
RECT rectangle;
GetClientRect(myHandle, &rectangle);
myWidth = rectangle.right - rectangle.left;
myHeight = rectangle.bottom - rectangle.top;
if (myWidth != 0 && myHeight != 0){
Event event;
event.Type = Event::Resized;
event.Size.Width = myWidth;
event.Size.Height = myHeight;
PushEvent(event);
}
break;
}
#include <cmath>
T Direction(){// May want to use double or float instead
return atan2(y, x);
}
T Dot(Vector2<T>& Other){//May want to use double or float instead
return x*Other.x + y*Other.y;
}
T Length(){
return sqrt(x*x + y*y);
}
void Normalize(){
T Length = Length();
x /= Length;
y /= Length;
}
#include <cmath>
Vector3<T>& Cross(Vector3<T>& Other){
return Vector3<T>(y*Other.z - Other.y*z, z*Other.x - x*Other.z, x*Other.y - y*Other.x);
}
T Dot(Vector3<T>& Other){
return x*Other.x + y*Other.y + z*Other.z;
}
T Length(){
return sqrt(x*x + y*y + z*z);
}
void Normalize(){
T Length = Length();
x /= Length;
y /= Length;
z /= Length;
}
#include <SFML/Graphics.hpp>
#include <iostream>
#include <string>
#include <list>
#include <map>
class ImageManager{
private:
std::map<std::string, sf::Image> images;
public:
ImageManager(){
}
sf::Image& Load(std::string file){
if (images.find(file) == images.end()){
images.insert(std::pair<std::string, sf::Image>(file, sf::Image()));
images[file] = sf::Image();
images[file].SetSmooth(false);
images[file].LoadFromFile(file);
}
return images[file];
}
~ImageManager(){
images.clear();
}
};
ImageManager Images;
class Object{
private:
sf::Sprite mySprite;
sf::String myFilename, myParameter1, myParameter2;
public:
Object(){
}
Object(double X, double Y, sf::String Filepath, sf::String Param1, sf::String Param2){
myFilename = Filepath;
mySprite.SetImage(Images.Load(Filepath), true);
mySprite.SetPosition(X, Y);
myParameter1 = Param1;
myParameter2 = Param2;
}
void LoadImage(sf::String Filepath){
mySprite.SetImage(Images.Load(Filepath), true);
}
sf::Sprite& GetSprite(){
return mySprite;
}
sf::String& GetParameter1(){
return myParameter1;
}
sf::String& GetParameter2(){
return myParameter2;
}
sf::String& GetFilename(){
return myFilename;
}
~Object(){
}
};
sf::RenderWindow Window;
std::string Command;
sf::Vector2f LevelSize;
sf::Mutex Mutex;
Object CurrentObject;
std::list<Object> Objects;
bool CompareStrings(std::string stringsrc, std::string stringval){
unsigned int length = stringval.length();
if (stringsrc.length() < length)
return false;
for (unsigned int i = 0; i < length; i++){
if (stringsrc[i] != stringval[i])
return false;
}
return true;
}
void Console(void*){
while (Window.IsOpened()){
std::cin >> Command;
if (CompareStrings(Command, "setsize")){
std::cout << "Please enter the new Level Width: ";
std::cin >> LevelSize.x;
std::cout << "Recieved " << LevelSize.x << ". Please enter the new Level Height: ";
std::cin >> LevelSize.y;
std::cout << "Recieved " << LevelSize.y << ".\n";
}
else if (CompareStrings(Command, "setwidth")){
std::cout << "Please enter the new Level Width: ";
std::cin >> LevelSize.x;
std::cout << "Recieved " << LevelSize.x << ".\n";
}
else if (CompareStrings(Command, "setheight")){
std::cout << "Please enter the new Level Height: ";
std::cin >> LevelSize.y;
std::cout << "Recieved " << LevelSize.y << ".\n";
}
else if (CompareStrings(Command, "getsize")){
std::cout << "Level Size is (" << LevelSize.x << ',' << LevelSize.y << ")\n";
}
else if (CompareStrings(Command, "setsprite")){
std::cout << "Please enter the filename of the new sprite: ";
std::string Filename;
std::cin >> Filename;
CurrentObject.GetFilename() = Filename;
CurrentObject.LoadImage(Filename);
std::cout << "Recieved " << Filename << ".\n";
}
else if (CompareStrings(Command, "setparameter1")){
std::cout << "Please enter the new value for Parameter 1: ";
std::string Param;
std::cin >> Param;
CurrentObject.GetParameter1() = Param;
std::cout << "Recieved " << Param << ".\n";
}
else if (CompareStrings(Command, "setparameter2")){
std::cout << "Please enter the new value for Parameter : ";
std::string Param;
std::cin >> Param;
CurrentObject.GetParameter2() = Param;
std::cout << "Recieved " << Param << ".\n";
}
else if (CompareStrings(Command, "getsprite")){
std::string Filename = CurrentObject.GetFilename();
std::cout << "The sprite's filename is " << Filename << ".\n";
}
else if (CompareStrings(Command, "getparameter1")){
std::string Param = CurrentObject.GetParameter1();
std::cout << "Parameter 1 is currently " << Param << ".\n";
}
else if (CompareStrings(Command, "getparameter2")){
std::string Param = CurrentObject.GetParameter2();
std::cout << "Parameter 2 is currently " << Param << ".\n";
}
else
std::cout << "Invalid Function\n";
}
}
int main(){
LevelSize.x = 512;
LevelSize.y = 512;
Window.Create(sf::VideoMode(512, 512, 32), "Level Editor", sf::Style::Close);
Window.SetFramerateLimit(50);
sf::Thread Thread(&Console);
Thread.Launch();
while (Window.IsOpened()){
sf::Event Event;
while (Window.GetEvent(Event)){
if (Event.Type == sf::Event::Closed || (Event.Type == sf::Event::KeyPressed && Event.Key.Code == sf::Key::Escape)){
Window.Close();
break;
}
}
CurrentObject.GetSprite().SetPosition(Window.GetInput().GetMouseX()-(Window.GetInput().GetMouseX()%4), Window.GetInput().GetMouseY()-(Window.GetInput().GetMouseY()%4));
Window.Clear();
Window.Draw(CurrentObject.GetSprite());
Window.Display();
}
return EXIT_SUCCESS;
}