[QUOTE=Richy19;25349213]OK so i have managed to show the windows form, but now the little Command Prompt wont close in the background
anyway to make it close and only show the window?[/QUOTE]
Change the System in Linker options to Windows instead of Console.
[QUOTE=animorten;25354851][code]LRESULT CALLBACK CRenderWindow::WindowProc(HWND hWnd, UINT uMsg, LPARAM lParam, WPARAM wParam)[/code]
[b]LPARAM lParam[/b] and [b]WPARAM wParam[/b] needs to swap places.[/QUOTE]
I can't believe I did that, do you mind beating me with a baseball bat?
Edit: Page King
Im trying to run this tutorial: [url]http://www.sfml-dev.org/tutorials/1.6/graphics-window.php[/url]
when i use the code on the tutorial
[code]#include <SFML/Graphics.hpp>
int main()
{
// Create the main rendering window
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
// Start game loop
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
// A key has been pressed
if (Event.Type == sf::Event::KeyPressed)
{
// Escape key : exit
if (Event.Key.Code == sf::Key::Escape)
App.Close();
}
}
// Clear the screen with red color
App.Clear();
// Display window contents on screen
App.Display();
}
return EXIT_SUCCESS;
}
[/code]
i get:
[quote]Segmentation fault
Process returned 139 (0x8B)[/quote]
yet when i remove the:
App.Clear();
it works (although the window gets full of static).
Using ubuntu, SFML 1.6 and i have an integrated graphics card if it matters
Where does it crash? Run a debugger.
EDIT: To clarify, while removing lines help debugging, it could be any call after that 'Clear' that actually crashes. Debugging without a debugger is futile :)
just ran the codeblocks debugger and got this
[quote]Debugger name and version: GNU gdb (GDB) 7.1-ubuntu
Program received signal SIGSEGV, Segmentation fault.
In sf::RenderTarget::Clear(sf::Color const&) () (/usr/lib/libsfml-graphics.so.1.5)
At /home/me/codeblocks/Bored/main.cpp:36[/quote]
[QUOTE=Richy19;25377482]just ran the codeblocks debugger and got this[/QUOTE]
Okay so it's really a chain of events from the clear call, weird.
[QUOTE=Richy19;25377482]just ran the codeblocks debugger and got this[/QUOTE]
If you're using 1.6 why does your library say 1.5? Might want to try and build the latest libs, actually you should probably just move to SFML2 and compile those.
[QUOTE=NorthernGate;25379604]If you're using 1.6 why does your library say 1.5? Might want to try and build the latest libs, actually you should probably just move to SFML2 and compile those.[/QUOTE]
I downloaded the 2.0 snapshot but i couldnt get it to compile in linux
would only work on my windows desktop :s
[QUOTE=Richy19;25379626]I downloaded the 2.0 snapshot but i couldnt get it to compile in linux
would only work on my windows desktop :s[/QUOTE]
I just tried and it compiled fine, apart from a few warnings out of stb_image.h which can be fixed by donwloading the [url=http://nothings.org/stb_image.c]newest one[/url] (the SFML guy (Laurent?) just renamed it ), using gcc 4.4.3 on 64-bit Linux. Also works fine with clang 1.1.
I build it via GNU Make and the supplied makefile.
what folder do you go into when you run the make command?
just the main sfml one?
also how do i check what version of GCC i have?
Yeah, just the sfml2 directory, which popped out of the gz.
gcc -v
do you use "sudo make install"?
Rather than clearing with the default, have you tried explicitly placing a color inside of it?
[QUOTE=Richy19;25380083]do you use "sudo make install"?[/QUOTE]
Well, I just executed make; install would just take care of copying the libraries to the lib-directory.
[editline]13th October 2010[/editline]
Using sudo make install worked fine too though (did a clear before, just in case).
how do you do clear?
[editline]13th October 2010[/editline]
[QUOTE=Chandler;25380190]Rather than clearing with the default, have you tried explicitly placing a color inside of it?[/QUOTE]
yea i tried using the color that the tutorial gives you as well
just tried sudo make to see if it would even compile and got:
[quote]../../src/SFML/Window/Linux/VideoModeImpl.cpp:31:35: error: X11/extensions/Xrandr.h: No such file or directory
../../src/SFML/Window/Linux/VideoModeImpl.cpp: In static member function ‘static std::vector<sf::VideoMode, std::allocator<sf::VideoMode> > sf::priv::VideoModeImpl::GetFullscreenModes()’:
../../src/SFML/Window/Linux/VideoModeImpl.cpp:56: error: ‘XRRScreenConfiguration’ was not declared in this scope
../../src/SFML/Window/Linux/VideoModeImpl.cpp:56: error: ‘config’ was not declared in this scope
../../src/SFML/Window/Linux/VideoModeImpl.cpp:56: error: ‘XRRGetScreenInfo’ was not declared in this scope
../../src/SFML/Window/Linux/VideoModeImpl.cpp:61: error: ‘XRRScreenSize’ was not declared in this scope
../../src/SFML/Window/Linux/VideoModeImpl.cpp:61: error: ‘sizes’ was not declared in this scope
../../src/SFML/Window/Linux/VideoModeImpl.cpp:61: error: ‘XRRConfigSizes’ was not declared in this scope
../../src/SFML/Window/Linux/VideoModeImpl.cpp:89: error: ‘XRRFreeScreenConfigInfo’ was not declared in this scope
../../src/SFML/Window/Linux/VideoModeImpl.cpp: In static member function ‘static sf::VideoMode sf::priv::VideoModeImpl::GetDesktopMode()’:
../../src/SFML/Window/Linux/VideoModeImpl.cpp:133: error: ‘XRRScreenConfiguration’ was not declared in this scope
../../src/SFML/Window/Linux/VideoModeImpl.cpp:133: error: ‘config’ was not declared in this scope
../../src/SFML/Window/Linux/VideoModeImpl.cpp:133: error: ‘XRRGetScreenInfo’ was not declared in this scope
../../src/SFML/Window/Linux/VideoModeImpl.cpp:137: error: ‘Rotation’ was not declared in this scope
../../src/SFML/Window/Linux/VideoModeImpl.cpp:137: error: expected ‘;’ before ‘currentRotation’
../../src/SFML/Window/Linux/VideoModeImpl.cpp:138: error: ‘currentRotation’ was not declared in this scope
../../src/SFML/Window/Linux/VideoModeImpl.cpp:138: error: ‘XRRConfigCurrentConfiguration’ was not declared in this scope
../../src/SFML/Window/Linux/VideoModeImpl.cpp:142: error: ‘XRRScreenSize’ was not declared in this scope
../../src/SFML/Window/Linux/VideoModeImpl.cpp:142: error: ‘sizes’ was not declared in this scope
../../src/SFML/Window/Linux/VideoModeImpl.cpp:142: error: ‘XRRConfigSizes’ was not declared in this scope
../../src/SFML/Window/Linux/VideoModeImpl.cpp:147: error: ‘XRRFreeScreenConfigInfo’ was not declared in this scope
make[2]: *** [../../src/SFML/Window/Linux/VideoModeImpl.o] Error 1
make[2]: Leaving directory `/home/me/sfml2/build/make'
make[1]: *** [window] Error 2
make[1]: Leaving directory `/home/me/sfml2/build/make'
make: *** [sfml] Error 2
me@me-laptop:~/sfml2$
[/quote]
got stuff before that ofc but thats where all the errors started, as its all to do with the videomode could it be anything to do with the fact i have an integrated graphics?
[QUOTE=Richy19;25380260]how do you do clear?[/QUOTE]
make clear
it simply removed all files created by make.
[editline]13th October 2010[/editline]
That is, if it was setup like one would expect :P
[editline]13th October 2010[/editline]
That is, if it was setup like one would expect :P
[QUOTE=Richy19;25380260]how do you do clear?
[editline]13th October 2010[/editline]
yea i tried using the color that the tutorial gives you as well
just tried sudo make to see if it would even compile and got:
got stuff before that ofc but thats where all the errors started, as its all to do with the videomode could it be anything to do with the fact i have an integrated graphics?[/QUOTE]
[quote]
../../src/SFML/Window/Linux/VideoModeImpl.cpp:31:35: [b]error: X11/extensions/Xrandr.h: No such file or directory[/b][/quote]
You need libxrandr-dev.
If you're running a debian-based linux distro try running:
[quote]sudo apt-get build-dep libsfml-dev[/quote]
woo hoo managed to compile it and install it
but now my projects are still linking with the old version...
I have managed to compile with the new SFML version by manually selecting the libraries.
But does anyone know if theres an easier way to select them like you did with the old files?
AKA -lsfml-system ...
Hi guys, i have a little problem, i have a function to generate a list of tiles(as pictureboxes (just in the editor)) it works fine so far but it really only does one tile, and i know there are two.
Here is the code:
[code]
public static void GenerateTileList(ref Panel parent)
{
Bitmap bmp = new Bitmap(@"content/textures/editor/textures.png");
int i = 1;
foreach (KeyValuePair<String, Microsoft.Xna.Framework.Rectangle> texture in textureBank)
{
MessageBox.Show(i.ToString() + "Out of:" + (textureBank.Count).ToString());
Vector2 Pos = Vector2.Zero;
PictureBox disposable = new PictureBox();
System.Drawing.Rectangle srcRect = new System.Drawing.Rectangle(texture.Value.X, texture.Value.Y, 32, 32);
disposable.Image = (Image) bmp;
parent.Controls.Add(disposable);
disposable.Size = new System.Drawing.Size(32, 32);
parent.CreateGraphics().DrawImage(disposable.Image, Pos.X, Pos.Y, srcRect, System.Drawing.GraphicsUnit.Pixel);
pBList.Add(
texture.Key,
disposable
);
Pos.X += 32; Pos.Y += 32;
i++;
}
}
[/code]
And here is the output from the messagebox:
[QUOTE=Messagebox.Show()]
---------------------------
---------------------------
1Out of:2
---------------------------
OK
---------------------------
[/QUOTE]
[QUOTE=Messagebox.Show()]
---------------------------
---------------------------
2Out of:2
---------------------------
OK
---------------------------
[/QUOTE]
But the parent panel only has one tile on it.
[b]*** Update: ***[/b]
I rewrote the function and fixed it:
[code]
public static void GenerateTileList(Panel parent)
{
Bitmap bmp = new Bitmap(@"content/textures/editor/textures.png");
System.Drawing.Point pt = new System.Drawing.Point(0, 0);
foreach (KeyValuePair<String, Microsoft.Xna.Framework.Rectangle> texture in textureBank)
{
pBList.Add(
texture.Key,
new PictureBox()
);
}
foreach (KeyValuePair<String, PictureBox> pb in pBList)
{
pb.Value.Image = (Image)bmp;
pb.Value.Size = new System.Drawing.Size(32, 32);
pb.Value.Location = pt;
parent.Controls.Add(pb.Value);
pb.Value.Show();
pt.X += 32;
if(pt.X >= 192)
pt.Y += 32;
}
}
[/code]
Argh, segfault at a weird area. For some reason this:
[code]while (cin >> new_word)
words.push_back(new_word);[/code]
causes Segmentation Fault. Anyone have any ideas? I haven't tried a debugger because I'm using gvim and I haven't tried to understand how to use a debugger with it.
Make sure [I]words[/I] is not a dangling reference (if it is a reference, of course).
But you should really get a debugger working. Are you even sure that's where the segfault is caused?
Shouldn't be. Here's the full code:
[code]#include <string>
#include <vector>
#include <iostream>
using std::vector;
using std::string;
using std::endl;
using std::cout;
using std::cin;
bool palindrome(const string& word)
{
typedef string::size_type str_sz;
int i;
str_sz wordsize = word.size();
str_sz halfword = wordsize/2;
while (i != halfword + 1) {
if (word[i] != (word[wordsize - i - 1])) {
return false;
}
++i;
}
return true;
}
vector<string> extract_palindromes(vector<string>& words)
{
vector<string> extracted;
for (vector<string>::const_iterator i = words.begin();
i != words.end(); ++i) {
if (palindrome(*i))
extracted.push_back(*i);
}
return extracted;
}
int main() {
vector<string> words;
cout << "Please enter a list of words followed by end-of-file."
<< endl << endl;
string new_word;
while (cin >> new_word)
words.push_back(new_word);
vector<string> palindromes;
palindromes = extract_palindromes(words);
cout << "There are " << palindromes.size() << " palindromes in that list!" << endl
<< "They are as follows:" << endl;
for (vector<string>::const_iterator i = palindromes.begin();
i != palindromes.end(); ++i)
cout << *i << endl;
return 0;
}[/code]
Yeah I'll do that just now actually.
Any idea why [cpp] tags aren't working?
If you're wondering about the basic level of programming, I'm doing a book exercise.
Compwhizii broke [cpp] tags. They're replaced by something though, I don't remember how to use them.
I can't figure out a way to make craftables in my Textcraft project, anyone have an idea on how i could do it? (my current code doesn't work if my craftables together uses the same items more than once).
Old, buggy code:
[cpp]public void Combine(Item itemA, Item itemB)
{
bool hasItems = false;
bool hasA = false;
bool hasB = false;
Item newItem = new Item("Invalid Item");
if (inventoryList.Contains(itemA) && inventoryList.Contains(itemB))
hasItems = true;
if (hasItems)
{
bool insideParsing = false;
TextReader textReader;
textReader = new StreamReader(FileSystem.defaultDir + "\\Items.txt");
foreach (string line in textReader.ReadToEnd().Split('\n'))
{
string l;
//Console.WriteLine(line);
if (!insideParsing)
{
if (line.ToLower().StartsWith("c{"))
{
insideParsing = true;
Console.WriteLine("Entering crafting parse");
}
}
else
{
if (line.ToLower().StartsWith("itema="))
{
l = line.Remove(0, 6);
l = l.Replace("\r", "");
Console.WriteLine("Item A = " + l);
if (l == itemA.ItemName || l == itemB.ItemName)
{
RemoveItem(itemA);
hasA = true;
}
continue;
}
if (line.ToLower().StartsWith("itemb="))
{
l = line.Remove(0, 6);
l.Replace(" ", "");
l = l.Replace("\r", "");
Console.WriteLine("Item B = " + l);
if (l == itemB.ItemName || l == itemA.ItemName)
{
RemoveItem(itemB);
hasB = true;
}
continue;
}
if (hasA && hasB)
{
if (line.ToLower().StartsWith("newitem="))
{
l = line.Remove(0, 8);
l = l.Replace("\r", "");
foreach (Item item in World.worldItems)
{
if (item.ItemName == l)
{
AddItem(item);
newItem.ItemName = l;
}
}
}
hasA = false;
hasB = false;
hasItems = false;
break;
}
}
l = null;
}
Console.WriteLine("Mixed " + itemA.ItemName.ToLower() + " with " + itemB.ItemName.ToLower() + " and got " + newItem.ItemName.ToLower() + ".");
}
else
{
TextBuffer.Add("You don't have enough of these items on you.");
}
}[/cpp]
This is how i create craftables in a text file:
[code]C{
ItemA=A
ItemB=B
NewItem=C
}[/code]
Does anyone know of a good file type for tile based maps? Each tile may have multiple properties, and maps could be up to 1024x1024.
I was trying to play around with the x86 FPU:
[img]http://ahb.me/Gdb[/img]
Here's my code:
[code]
use16
org 0x7c00
xor ah, ah
mov al, 0x13
int 0x10
mov ax, 0xa000
mov es, ax
xor bx, bx
mov al, 2
l:
fld1
fist word [es:bx]
add bx, 2
cmp bx, 30000
jl l
cli
hlt
times 510-($-$$) db 0
db 0x55
db 0xAA
[/code]
[editline]16th October 2010[/editline]
Nevermind, forgot the initialize the FPU. For future reference, FINIT
[QUOTE=nos217;25423906]Shouldn't be. Here's the full code:
[code]#include <string>
#include <vector>
#include <iostream>
using std::vector;
using std::string;
using std::endl;
using std::cout;
using std::cin;
bool palindrome(const string& word)
{
typedef string::size_type str_sz;
int i;
str_sz wordsize = word.size();
str_sz halfword = wordsize/2;
while (i != halfword + 1) {
if (word[i] != (word[wordsize - i - 1])) {
return false;
}
++i;
}
return true;
}
vector<string> extract_palindromes(vector<string>& words)
{
vector<string> extracted;
for (vector<string>::const_iterator i = words.begin();
i != words.end(); ++i) {
if (palindrome(*i))
extracted.push_back(*i);
}
return extracted;
}
int main() {
vector<string> words;
cout << "Please enter a list of words followed by end-of-file."
<< endl << endl;
string new_word;
while (cin >> new_word)
words.push_back(new_word);
vector<string> palindromes;
palindromes = extract_palindromes(words);
cout << "There are " << palindromes.size() << " palindromes in that list!" << endl
<< "They are as follows:" << endl;
for (vector<string>::const_iterator i = palindromes.begin();
i != palindromes.end(); ++i)
cout << *i << endl;
return 0;
}[/code]
Yeah I'll do that just now actually.
Any idea why [cpp] tags aren't working?
If you're wondering about the basic level of programming, I'm doing a book exercise.[/QUOTE]
palindrome-function: i is uninitialized.
Next time, compile with some warnings enabled ;)
[QUOTE=Dj-J3;25424667]I can't figure out a way to make craftables in my Textcraft project, anyone have an idea on how i could do it? (my current code doesn't work if my craftables together uses the same items more than once).
Old, buggy code:
[code]public void Combine(Item itemA, Item itemB)
{
bool hasItems = false;
bool hasA = false;
bool hasB = false;
Item newItem = new Item("Invalid Item");
if (inventoryList.Contains(itemA) && inventoryList.Contains(itemB))
hasItems = true;
if (hasItems)
{
bool insideParsing = false;
TextReader textReader;
textReader = new StreamReader(FileSystem.defaultDir + "\\Items.txt");
foreach (string line in textReader.ReadToEnd().Split('\n'))
{
string l;
//Console.WriteLine(line);
if (!insideParsing)
{
if (line.ToLower().StartsWith("c{"))
{
insideParsing = true;
Console.WriteLine("Entering crafting parse");
}
}
else
{
if (line.ToLower().StartsWith("itema="))
{
l = line.Remove(0, 6);
l = l.Replace("\r", "");
Console.WriteLine("Item A = " + l);
if (l == itemA.ItemName || l == itemB.ItemName)
{
RemoveItem(itemA);
hasA = true;
}
continue;
}
if (line.ToLower().StartsWith("itemb="))
{
l = line.Remove(0, 6);
l.Replace(" ", "");
l = l.Replace("\r", "");
Console.WriteLine("Item B = " + l);
if (l == itemB.ItemName || l == itemA.ItemName)
{
RemoveItem(itemB);
hasB = true;
}
continue;
}
if (hasA && hasB)
{
if (line.ToLower().StartsWith("newitem="))
{
l = line.Remove(0, 8);
l = l.Replace("\r", "");
foreach (Item item in World.worldItems)
{
if (item.ItemName == l)
{
AddItem(item);
newItem.ItemName = l;
}
}
}
hasA = false;
hasB = false;
hasItems = false;
break;
}
}
l = null;
}
Console.WriteLine("Mixed " + itemA.ItemName.ToLower() + " with " + itemB.ItemName.ToLower() + " and got " + newItem.ItemName.ToLower() + ".");
}
else
{
TextBuffer.Add("You don't have enough of these items on you.");
}
}[/code]
This is how i create craftables in a text file:
[code]C{
ItemA=A
ItemB=B
NewItem=C
}[/code][/QUOTE]
You mean ItemA == ItemB (references are equal)? If so, could it be a problem to remove the same item twice?
[QUOTE=jmazouri;25429232]Does anyone know of a good file type for tile based maps? Each tile may have multiple properties, and maps could be up to 1024x1024.[/QUOTE]
I don't really know one on top of my head, but a simple binary format would do, would it not?
Like
[code]header:
magic bytes
xsize: 10bits (or if you want it easier to parse, 2bytes)
ysze: 10bits
This header is followed by xsize*ysize elements, ordered however you like
element:
numProperites: 1byte (leaves room for [minProperties..255 + minProperties] properties)
this is followed by numProperties property-types[/code]
Ah of course. Thanks very much haha.
[QUOTE=ZeekyHBomb;25434353]You mean ItemA == ItemB (references are equal)? If so, could it be a problem to remove the same item twice?
[/QUOTE]
I'll try to give an example.
[code]
C{
ItemA=Lava
ItemB=Water
NewItem=Obsidian
}
C{
ItemA=Lava
ItemB=Sand
NewItem=Glass
}[/code]
if i would craft lava and sand together, i'd get obsidian, or "invalid item"(not completely sure tbh). The cause is unknown to me. :confused:
I'm guessing it has to do with the order of how i create them in the text file. Obviously, i need a way to make it independant from that.
[editline].[/editline]
There would probably be a problem removing the same item twice, but it's only doing that if, for example ItemA or ItemB = what the player entered when he wrote the crafting command, and i haven't done that.
Oh yeah, now I get it.
Well, you should stop parsing the insideParsing-stuff upon encountering a }. Upon that even you can also check if hasA && hasB (not before) and if that is true, break out of the loop; else continue (in which case it would yet again try to find a "c{").
I hope this is not the road you plan on going though. You should parse the file properly and lay it into a structure in memory somehow.
Funny thing, I am doing the same shit at this moment as well :D
Not file parsing, but a C++ class for items that can also possibly be combined and produce results. Parsing this info from a file is trivial though.
Sorry, you need to Log In to post a reply to this thread.