SFML community forums

General => SFML projects => Topic started by: tgm on April 29, 2008, 06:26:47 pm

Title: TGMs small patches
Post by: tgm on April 29, 2008, 06:26:47 pm
Well, this is no actual project... anyway.. this is the placer, where I'm going to release small additions etc for SFML.. I would love to see them in the SVN ;) everything I gonna post within this thread can be used without any license.. (and of course without any warranty ;) )
bla bla.. lets get started ^^
Title: First addition: ClipRegion
Post by: tgm on April 29, 2008, 06:29:08 pm
This function will limit the rendering to a given region.. everything outside this region will be cliped..
the second funktion will clear all cliping, so that rendering will continue like before..
Code: [Select]

#include <SFML/Graphics.hpp>

#include <iostream>

void SetClipRegion(sf::FloatRect Region)
double plane [4]={0,0,0,0};

  glClipPlane(GL_CLIP_PLANE0, &plane[0]);
  glClipPlane(GL_CLIP_PLANE1, &plane[0]);
  glClipPlane(GL_CLIP_PLANE2, &plane[0]);
  glClipPlane(GL_CLIP_PLANE3, &plane[0]);


void ClearClipRegion()

greetz TGM
Title: TGMs small patches
Post by: Laurent on April 30, 2008, 03:14:26 am
I was also thinking about using clip planes for this (as all other solutions, including scissor rect, all have their disadvantages) ; I just need now to find a nice way to integrate this to the existing system (there are a few things to care about).

But yes, this kind of code will definitively be part of SFML soon ;)
Title: TGMs small patches
Post by: tgm on April 30, 2008, 01:40:02 pm
Acctualy this solution works qiute well (for me, at least)
all one has to do is puting this code into a *.hpp including it and well.. it works fine with a normal RenderWindow..
Title: TGMs small patches
Post by: Laurent on April 30, 2008, 02:39:27 pm
I know, technically it works fine ;)

The most difficult part is to find a convenient public interface, integrate this nicely into the view / window / drawable system (must it be local to a view ? or be in window coordinates ? local to drawables ?), etc... in short : make it convenient yet powerful for everybody. That's always the most difficult part (technically, running simple 2D with OpenGL is quite straight-forward).
Title: TGMs small patches
Post by: tgm on May 01, 2008, 01:13:36 pm
^^ well, thats the part, I cannot help you with ;)
(though I have to say, I love the way you designed your Lib...)
Title: TGMs small patches
Post by: pamaury on May 01, 2008, 02:23:00 pm
That's only a suggestion but I believe clipping should be relative to the view. Why ? Because if a clipping relative to window while they are views doesn't make sense in my opinion. Moreover a clipping relative to drawable would be too advanced and probably useless, and it could also lead to poor performance if the clipping region is changed 100 times or more each frame.
For the interface, one interesting question is whether the window should handle it or the view. I mean, it would be interesting that the view handles the clipping region because a clipping relative to a view...without a view is a non-sense :).
Perhaps you should create an abstract class named 'ViewClipper' with only two methods for now: "Enable","Disable". When a view is setuped, the Enable method is called and when the view is removed, the Disable method is called. One advantage is that all the logic is in the class that implements it: the window doesn't have to know how to do clipping. Another advantage is that if you want to implement several kinds of clipping, there is no problem(sometimes an advance clipping with stencil buffer can be useful for example whereas for basic things, clipping planes are far better). But one is that if you want to support some non-Opengl back-end(it depends on how you implement the software rendered) then you have to code one implementation for each renderer...

Anyway I'm sure you will find a correct interface for it and I agree with you when you say that's probably the main difficulty.