SFML community forums

Help => Graphics => Topic started by: hayer on April 04, 2011, 11:39:26 am

Title: Making a shape with textures, how?
Post by: hayer on April 04, 2011, 11:39:26 am
Hi

I want to make a sf::Shape that can have like 4 different textures.. After a bit of research I realized that couldn't be done straight out of the box.

So I was thinking of doing like I did when I made my DBPro map edtior.
Have 4 textuers and a shader. Then the polygon is painted with four different colors. Each colors represents a texture.

ex:
255, 000, 000 - Grass
000, 255, 000 - Stone
000, 000, 255 - Blood
255, 255, 255 - Gravel

Then the shader would do its magic. But as far is I know this neither is doable with SFML because it only takes whole-fcking-screen shaders, right?

Sooo.. any help?
Title: Making a shape with textures, how?
Post by: Laurent on April 04, 2011, 12:12:40 pm
SFML 2 has shaders that can be applied to individual drawables.
Title: Making a shape with textures, how?
Post by: hayer on April 04, 2011, 01:15:57 pm
Okey, two questions then..

1. How do I compile SFML 2?

2. How can I add my own classes?
At the moment I'm using version 1.6 and tried to add my own class, but when I recompiled it, it still didn't show up..


Edit..

Don't know who or what cmake is, but it seems to fail cause of a user-input. >_>

Log
Code: [Select]

agrualon@mikkel-laptop:~/SFML-2.0-snapshot$ cmake CMakeLists.txt
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of void*
-- Check size of void* - done
-- Looking for XOpenDisplay in /usr/lib/libX11.so;/usr/lib/libXext.so
-- Looking for XOpenDisplay in /usr/lib/libX11.so;/usr/lib/libXext.so - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for connect
-- Looking for connect - found
-- Looking for remove
-- Looking for remove - found
-- Looking for shmat
-- Looking for shmat - found
-- Looking for IceConnectionNumber in ICE
-- Looking for IceConnectionNumber in ICE - found
-- Found X11: /usr/lib/libX11.so
CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:70 (MESSAGE):
  Could NOT find Freetype (missing: FREETYPE_LIBRARY FREETYPE_INCLUDE_DIRS)
Call Stack (most recent call first):
  /usr/share/cmake-2.8/Modules/FindFreetype.cmake:92 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  src/SFML/Graphics/CMakeLists.txt:62 (find_package)


-- Configuring incomplete, errors occurred!
Title: Making a shape with textures, how?
Post by: Laurent on April 04, 2011, 01:26:58 pm
Quote
1. How do I compile SFML 2?

http://www.sfml-dev.org/tutorials/2.0/compile-with-cmake.php

Quote
2. How can I add my own classes?

To SFML? Why would you do that?

Quote
Could NOT find Freetype

You must install FreeType ;)
And all other libraries SFML depends on, if you don't have them.
Title: Making a shape with textures, how?
Post by: hayer on April 04, 2011, 01:38:17 pm
After installing libopenal1, libopenal-dev, libjpeg62-dev, libjpeg62, libfreetype6, libfreetype6-dev I get this error

Code: [Select]

agrualon@mikkel-laptop:~/SFML-2.0-snapshot$ cmake CMakeLists.txt
-- Could NOT find SNDFILE  (missing:  SNDFILE_INCLUDE_DIR SNDFILE_LIBRARY)
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
GLEW_INCLUDE_PATH
   used as include directory in directory /home/agrualon/SFML-2.0-snapshot/src/SFML/Graphics
GLEW_LIBRARY
    linked by target "sfml-graphics" in directory /home/agrualon/SFML-2.0-snapshot/src/SFML/Graphics
SNDFILE_INCLUDE_DIR (ADVANCED)
   used as include directory in directory /home/agrualon/SFML-2.0-snapshot/src/SFML/Audio

-- Configuring incomplete, errors occurred!
Title: Making a shape with textures, how?
Post by: Laurent on April 04, 2011, 01:41:15 pm
You must install libglew and libsndfile.

By the way, when you install libxxx-dev you automatically get libxxx, no need to install it manually.
Title: Making a shape with textures, how?
Post by: hayer on April 04, 2011, 01:48:47 pm
Well, got some futher, now I get;

||=== SFML, all ===|
/home/agrualon/SFML-2.0-snapshot/src/SFML/Window/Linux/VideoModeImpl.cpp|31|fatal error: X11/extensions/Xrandr.h: No such file or directory|
||=== Build finished: 1 errors, 0 warnings ===|


In Code::Blocks.
Title: Making a shape with textures, how?
Post by: Laurent on April 04, 2011, 01:58:50 pm
You must install libxrandr.

By the way, the list is in the tutorial
http://www.sfml-dev.org/tutorials/1.6/start-linux.php
Title: Making a shape with textures, how?
Post by: hayer on April 04, 2011, 02:24:15 pm
Well, got it compiled and did a minor re-write of my source code.. But now I get

Code: [Select]

/home/agrualon/Cpp Projects/My SFML Test/main.cpp||In function ‘int main()’:|
/home/agrualon/Cpp Projects/My SFML Test/main.cpp|105|warning: comparison between signed and unsigned integer expressions|
/home/agrualon/Cpp Projects/My SFML Test/main.cpp||In function ‘void DrawShapes()’:|
/home/agrualon/Cpp Projects/My SFML Test/main.cpp|278|warning: comparison between signed and unsigned integer expressions|
/home/agrualon/SFML-2.0-snapshot-build/lib/libsfml-window.so||undefined reference to `XRRConfigCurrentConfiguration'|
/home/agrualon/SFML-2.0-snapshot-build/lib/libsfml-window.so||undefined reference to `XRRSetScreenConfig'|
/home/agrualon/SFML-2.0-snapshot-build/lib/libsfml-window.so||undefined reference to `XRRFreeScreenConfigInfo'|
/home/agrualon/SFML-2.0-snapshot-build/lib/libsfml-window.so||undefined reference to `XRRGetScreenInfo'|
/home/agrualon/SFML-2.0-snapshot-build/lib/libsfml-window.so||undefined reference to `XRRConfigSizes'|
||=== Build finished: 5 errors, 2 warnings ===|


A couple of functions that aren't defined?_?
Title: Making a shape with textures, how?
Post by: Laurent on April 04, 2011, 02:57:40 pm
Did you compile SFML statically (BUILD_SHARE_LIBS=FALSE)?
Title: Making a shape with textures, how?
Post by: hayer on April 04, 2011, 03:04:22 pm
Well, another error-log

Code: [Select]

/home/agrualon/SFML-2.0-snapshot-build/lib/libsfml-window-s.a(VideoModeImpl.cpp.o)||In function `sf::priv::VideoModeImpl::GetDesktopMode()':|
VideoModeImpl.cpp|| undefined reference to `XOpenDisplay'|
VideoModeImpl.cpp|| undefined reference to `XQueryExtension'|
VideoModeImpl.cpp|| undefined reference to `XCloseDisplay'|
VideoModeImpl.cpp|| undefined reference to `XRRGetScreenInfo'|
VideoModeImpl.cpp|| undefined reference to `XRRConfigCurrentConfiguration'|
VideoModeImpl.cpp|| undefined reference to `XRRConfigSizes'|
VideoModeImpl.cpp|| undefined reference to `XRRFreeScreenConfigInfo'|
/home/agrualon/SFML-2.0-snapshot-build/lib/libsfml-window-s.a(VideoModeImpl.cpp.o)||In function `sf::priv::VideoModeImpl::GetFullscreenModes()':|
VideoModeImpl.cpp|| undefined reference to `XOpenDisplay'|
VideoModeImpl.cpp|| undefined reference to `XQueryExtension'|
VideoModeImpl.cpp|| undefined reference to `XCloseDisplay'|
VideoModeImpl.cpp|| undefined reference to `XRRGetScreenInfo'|
VideoModeImpl.cpp|| undefined reference to `XRRConfigSizes'|
VideoModeImpl.cpp|| undefined reference to `XListDepths'|
VideoModeImpl.cpp|| undefined reference to `XFree'|
VideoModeImpl.cpp|| undefined reference to `XRRFreeScreenConfigInfo'|
/home/agrualon/SFML-2.0-snapshot-build/lib/libsfml-window-s.a(WindowImplX11.cpp.o)||In function `sf::priv::WindowImplX11::KeysymToSF(unsigned long)':|
WindowImplX11.cpp|| undefined reference to `XConvertCase'|
/home/agrualon/SFML-2.0-snapshot-build/lib/libsfml-window-s.a(WindowImplX11.cpp.o)||In function `sf::priv::WindowImplX11::CleanUp()':|
WindowImplX11.cpp|| undefined reference to `XRRGetScreenInfo'|
WindowImplX11.cpp|| undefined reference to `XRRConfigCurrentConfiguration'|
WindowImplX11.cpp|| undefined reference to `XRRSetScreenConfig'|
WindowImplX11.cpp|| undefined reference to `XRRFreeScreenConfigInfo'|
/home/agrualon/SFML-2.0-snapshot-build/lib/libsfml-window-s.a(WindowImplX11.cpp.o)||In function `sf::priv::WindowImplX11::ProcessEvent(_XEvent)':|
WindowImplX11.cpp|| undefined reference to `XQueryKeymap'|
WindowImplX11.cpp|| undefined reference to `XLookupString'|
WindowImplX11.cpp|| undefined reference to `XFilterEvent'|
WindowImplX11.cpp|| undefined reference to `Xutf8LookupString'|
WindowImplX11.cpp|| undefined reference to `XUnsetICFocus'|
WindowImplX11.cpp|| undefined reference to `XSetICFocus'|
WindowImplX11.cpp|| undefined reference to `XLookupString'|
WindowImplX11.cpp|| undefined reference to `XLookupString'|
/home/agrualon/SFML-2.0-snapshot-build/lib/libsfml-window-s.a(WindowImplX11.cpp.o)||In function `sf::priv::WindowImplX11::CreateHiddenCursor()':|
WindowImplX11.cpp|| undefined reference to `XCreatePixmap'|
WindowImplX11.cpp|| undefined reference to `XCreateGC'|
WindowImplX11.cpp|| undefined reference to `XDrawPoint'|
WindowImplX11.cpp|| undefined reference to `XFreeGC'|
WindowImplX11.cpp|| undefined reference to `XCreatePixmapCursor'|
WindowImplX11.cpp|| undefined reference to `XFreePixmap'|
/home/agrualon/SFML-2.0-snapshot-build/lib/libsfml-window-s.a(WindowImplX11.cpp.o)||In function `sf::priv::WindowImplX11::SetIcon(unsigned int, unsigned int, unsigned char const*)':|
WindowImplX11.cpp|| undefined reference to `XCreateImage'|
WindowImplX11.cpp|| undefined reference to `XCreatePixmap'|
WindowImplX11.cpp|| undefined reference to `XCreateGC'|
WindowImplX11.cpp|| undefined reference to `XPutImage'|
WindowImplX11.cpp|| undefined reference to `XFreeGC'|
WindowImplX11.cpp|| undefined reference to `XCreatePixmapFromBitmapData'|
WindowImplX11.cpp|| undefined reference to `XAllocWMHints'|
WindowImplX11.cpp|| undefined reference to `XSetWMHints'|
WindowImplX11.cpp|| undefined reference to `XFree'|
WindowImplX11.cpp|| undefined reference to `XFlush'|
/home/agrualon/SFML-2.0-snapshot-build/lib/libsfml-window-s.a(WindowImplX11.cpp.o)||In function `sf::priv::WindowImplX11::Show(bool)':|
WindowImplX11.cpp|| undefined reference to `XUnmapWindow'|
WindowImplX11.cpp|| undefined reference to `XMapWindow'|
/home/agrualon/SFML-2.0-snapshot-build/lib/libsfml-window-s.a(WindowImplX11.cpp.o)||In function `sf::priv::WindowImplX11::SetTitle(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':|
WindowImplX11.cpp|| undefined reference to `XStoreName'|
/home/agrualon/SFML-2.0-snapshot-build/lib/libsfml-window-s.a(WindowImplX11.cpp.o)||In function `sf::priv::WindowImplX11::SetSize(unsigned int, unsigned int)':|
WindowImplX11.cpp|| undefined reference to `XResizeWindow'|
/home/agrualon/SFML-2.0-snapshot-build/lib/libsfml-window-s.a(WindowImplX11.cpp.o)||In function `sf::priv::WindowImplX11::SetPosition(int, int)':|
WindowImplX11.cpp|| undefined reference to `XMoveWindow'|
/home/agrualon/SFML-2.0-snapshot-build/lib/libsfml-window-s.a(WindowImplX11.cpp.o)||In function `sf::priv::WindowImplX11::SetCursorPosition(unsigned int, unsigned int)':|
WindowImplX11.cpp|| undefined reference to `XWarpPointer'|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build finished: 50 errors, 0 warnings ===|
Title: Making a shape with textures, how?
Post by: Laurent on April 04, 2011, 03:10:32 pm
I was not telling you to do so, I was just waiting for an answer, and eventually tell you *not* to build SFML statically under Linux.

Did you install libxrandr-dev?
Title: Making a shape with textures, how?
Post by: hayer on April 04, 2011, 03:17:18 pm
Oh, my mistake. Yes, I've installed libxrandr-dev and just changed back the libs.
Title: Making a shape with textures, how?
Post by: hayer on April 04, 2011, 04:09:18 pm
Okey, tried to include /usr/include/X11 - didnt work, then I tried /usr/include/ which didnt work netiher.. Tried to reinstall some packages. Rebooted.

Still not working.

Edit: Don't know what I just did; but now Im getting

Code: [Select]

/home/agrualon/Cpp Projects/My SFML Test/main.cpp||In function ‘int main()’:|
/home/agrualon/Cpp Projects/My SFML Test/main.cpp|107|warning: comparison between signed and unsigned integer expressions|
/home/agrualon/Cpp Projects/My SFML Test/main.cpp||In function ‘void DrawShapes()’:|
/home/agrualon/Cpp Projects/My SFML Test/main.cpp|283|warning: comparison between signed and unsigned integer expressions|
/home/agrualon/SFML-2.0-snapshot-build/lib/libsfml-window.so||undefined reference to `XRRConfigCurrentConfiguration'|
/home/agrualon/SFML-2.0-snapshot-build/lib/libsfml-window.so||undefined reference to `XRRSetScreenConfig'|
/home/agrualon/SFML-2.0-snapshot-build/lib/libsfml-window.so||undefined reference to `XRRFreeScreenConfigInfo'|
/home/agrualon/SFML-2.0-snapshot-build/lib/libsfml-window.so||undefined reference to `XRRGetScreenInfo'|
/home/agrualon/SFML-2.0-snapshot-build/lib/libsfml-window.so||undefined reference to `XRRConfigSizes'|
||=== Build finished: 5 errors, 2 warnings ===|
Title: Making a shape with textures, how?
Post by: Laurent on April 04, 2011, 04:26:18 pm
Quote
Edit: Don't know what I just did; but now Im getting

Isn't it the same as before?
Title: Making a shape with textures, how?
Post by: hayer on April 04, 2011, 04:35:34 pm
Well, yea - but had some problems getting C::B to understand that I was not using the static-lib anymore  :oops:
Title: Making a shape with textures, how?
Post by: hayer on April 04, 2011, 04:55:43 pm
This guy seems to be having the same problem as me http://www.sfml-dev.org/forum-fr/viewtopic.php?p=32501&sid=82780daf2eb630dafe9e09770dbf99ec

but I don't speak French..
Title: Making a shape with textures, how?
Post by: Laurent on April 04, 2011, 05:14:34 pm
There's no answer in this topic.

We just noticed that the problem was specific to Fedora (is this what you use?).
Title: Making a shape with textures, how?
Post by: hayer on April 04, 2011, 05:23:45 pm
No, I'm using Ubuntu 10.10 ...
Title: Making a shape with textures, how?
Post by: hayer on April 04, 2011, 05:37:29 pm
Okey, recompiled it, got it working..

But now my app just crashes with the message "Segmentation fault"..
The source code is a bit huge, so I'll try to isolate it. But maybe it have something to do with all the sf::Shape s = sf::Shape::Circle that I'm using?
Title: Making a shape with textures, how?
Post by: hayer on April 04, 2011, 06:34:58 pm
Okey, got a shader working, or at least in the WYSWIG editor.. What now?

How do I apply a shader to only one shape? or sprite?

Edit: Didn't see the Draw( sprite , shader ) when I read the src the first time, sorry.
Title: Making a shape with textures, how?
Post by: Laurent on April 04, 2011, 07:18:30 pm
So finally what was wrong with XRandr?
Title: Making a shape with textures, how?
Post by: hayer on April 04, 2011, 08:09:48 pm
I'm sorry, but I don't really know - just recompiled for the 4th time and it worked  :?:
Title: Making a shape with textures, how?
Post by: hayer on April 10, 2011, 03:35:14 pm
Okey, I've been toying around with shaders for a couple of days getting nowhere.. So now over to the next idea.

I was thinking some thing along texture splatting(For those not familar with the conecpt; http://en.wikipedia.org/wiki/Texture_splatting). Using texture splatting I would try to achive something like this;

(http://en.wikipedia.org/wiki/File:Texture_splatting.png)

I'll get back later today with some questions and maybe some tricks.

If any of you got tips for better performance with SFML + alphamap then please repley :)