Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: TGMs small patches  (Read 9163 times)

0 Members and 1 Guest are viewing this topic.

tgm

  • Jr. Member
  • **
  • Posts: 69
    • View Profile
TGMs small patches
« 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 ^^

tgm

  • Jr. Member
  • **
  • Posts: 69
    • View Profile
First addition: ClipRegion
« Reply #1 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)
{
glEnable(GL_CLIP_PLANE0);
  glEnable(GL_CLIP_PLANE1);
  glEnable(GL_CLIP_PLANE2);
  glEnable(GL_CLIP_PLANE3);
 
double plane [4]={0,0,0,0};

plane[1]=1;
plane[3]=-Region.Top;
  glClipPlane(GL_CLIP_PLANE0, &plane[0]);
 
  plane[1]=-1;
  plane[3]=Region.Bottom;
  glClipPlane(GL_CLIP_PLANE1, &plane[0]);
 
  plane[0]=1;
  plane[1]=0;
plane[3]=-Region.Left;
  glClipPlane(GL_CLIP_PLANE2, &plane[0]);
 
  plane[0]=-1;
  plane[3]=Region.Right;
  glClipPlane(GL_CLIP_PLANE3, &plane[0]);
 

}

void ClearClipRegion()
{
glDisable(GL_CLIP_PLANE0);
glDisable(GL_CLIP_PLANE1);
glDisable(GL_CLIP_PLANE2);
glDisable(GL_CLIP_PLANE3);
}

greetz TGM

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
TGMs small patches
« Reply #2 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 ;)
Laurent Gomila - SFML developer

tgm

  • Jr. Member
  • **
  • Posts: 69
    • View Profile
TGMs small patches
« Reply #3 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..

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
TGMs small patches
« Reply #4 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).
Laurent Gomila - SFML developer

tgm

  • Jr. Member
  • **
  • Posts: 69
    • View Profile
TGMs small patches
« Reply #5 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...)

pamaury

  • Newbie
  • *
  • Posts: 31
    • View Profile
TGMs small patches
« Reply #6 on: May 01, 2008, 02:23:00 pm »
Hi,
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.