Re : Layered Display

Ok Will, I don’t really see how it could work but seems interesting anyway.
Let me know if you have more info.

Thank you for this note.

Julien

----- Message d’origine ----De : Will Langford
? : A list for developers using the SDL library. (includes SDL-announce)
Envoy? le : Jeudi, 12 Juin 2008, 12h28mn 24s
Objet : Re: [SDL] Layered Display

I think the Julian I knew spelled his name with an ‘a’ rather than an
’e’… so… yeah.

Anyway, he had a really funky idea that worked pretty good as a faux z
buffer as a per pixel paralax scrolling setup. I can’t recall the
details :). Was a bright guy.

-Will


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

  _____________________________________________________________________________ 

Envoyez avec Yahoo! Mail. Une boite mail plus intelligente http://mail.yahoo.fr

Jonny, Edward,

I think your remark is right, I need to add functions for controlling colorkeys and alpha values. Took note of that.
The javadoc you sent to me gave me an idea, I could add a function to control the visibility of a specific layer.

As for the limit of 255 layers, I’m quite confused by what you said, maybe a misunderstanding. My opinion is,
clearly, a maximum of 255 layers is far enough, maybe that’s what you meant too ? Most applications should not
exceed, let’s say, 4 layers I guess …

As for the javadoc, it is an object oriented way to treat the problem, instead of managing the layer itself, we
change the state of the objects on the layers … that’s how I understood it. Anyway, it’s nice you sent it to me.
At least for this “visibility” stuff I did not think about.

Maybe a way to change the layers order could be an idea too.

Thank you guys, nice to have feedbacks from you.

Julien

----- Message d’origine ----De : Edward Byard <e_byard at yahoo.co.uk>
? : A list for developers using the SDL library. (includes SDL-announce)
Envoy? le : Jeudi, 12 Juin 2008, 20h32mn 34s
Objet : Re: [SDL] Layered Display

Hi,

I didn’t really finish my email off very well…

The system I used was developed exclusively for game development, and although written in Java using
heavily abstracted OpenGL, it was great. I don’t have the source, only the javadoc (some of which is
below). I’m not saying it needs to be this complicated…

The main “control” of which layer your surface (“Component”) was drawn on is the setDepth method, but as you can see the API
has loads of methods to do just about everything you could want.

Apologies to people who get plain-text emails only

Regards
Ed

Method Summary
void enableClipping(boolean enable)
Enables or disables the clipping for the component.
int getAbsoluteTopLeftX()
Returns the x coordinate of the absolute location of this component.
int getAbsoluteTopLeftY()
Returns the y coordinate of the absolute location of this component.
int getAbsoluteX()
Returns the x coordinate of the absolute location of this component.
int getAbsoluteY()
Returns the y coordinate of the absolute location of this component.
int getBlend()
Returns the alpha blend level.
int getDepth()
Returns the depth (or z-value) of the component.
int getHandleX()
Returns the x coordinate of the component’s handle.
int getHandleY()
Returns the y coordinate of the component’s handle.
int getHeight()
Returns the height of the component surface.
java.lang.String getName()
Returns the name of the node.
Container getParent()
Returns the parent of this Component.
double getRotationAngle()
Returns the rotation angle.
double getRotationCenterX()
Returns the horizontal center of rotation.
double getRotationCenterY()
Returns the vertical center of rotation.
int getScaledHeight()
Returns the height coordinate of the scaled component.
int getScaledWidth()
Returns the width coordinate of the scaled component.
double getScaleX()
Returns the horizontal scale.
double getScaleY()
Returns the vertical scale.
Surface getSurface()
Returns the component’s current surface.
int getTopLeftX()
Returns the x coordinate of the component’s top-left corner.
int getTopLeftY()
Returns the y coordinate of the component’s top-left corner.
int getWidth()
Returns the width of the component surface.
int getX()
Returns the X coordinate of this component.
int getY()
Returns the Y coordinate of this component.
boolean isAlphaSensibilityEnabled()
Returns the state of the alpha-mask-tolerance-based event response flag.
boolean isAutoScaleEnabled()
Checks if the surface’s auto-scaling feauture is enabled.
boolean isChild(Component component)
Tests if this Component is child of a given Component object; by definition only a Container can be parent, so a call to this method is sensible only from a Container instance.
boolean isClippingEnabled()
Checks if clipping is enabled or not.
boolean isEnabled()
Returns the state of the event response ability flag.
boolean isLocationAlphaSensitive(int x, int y)
Checks if pixel specified by given coords (x, y) is alpha-mask tolerated.
boolean isPressed()
Checks if the component is pressed.
boolean isScaleHandleEnabled()
Checks if the handle’s scaling feauture is enabled.
boolean isTransparent()
Return a value that specifies if the background fill color is transparent or not.
boolean isVisible()
Tests if the component is visible.
void mouseDragged(MouseEvent event)
Method executed when the mouse cursor is moved in the screen while the button is pressed.
void mousePressed(MouseEvent event)
Method executed when a mouse button is pressed.
void mouseReleased(MouseEvent event)
Method executed when a mouse button is released.
void setAlphaSensibilityEnabled(boolean enabled)
Sets the state of the alpha sensibility feature.
void setAutoScaleEnabled(boolean autoScale)
Activates/deactivates the component’s auto-scaling feature.
void setBlend(int blend)
Sets the alpha blend level in the range 0 (transparent) - 100 (opaque).
void setBlendFunction(BlendFunction bFunction)

void setDepth(int depth)
Sets the depth of the component and tell parent about this change in order parent can make effective any sort of children re-organization.
void setEnabled(boolean enabled)
Sets the state of the event response ability flag.
void setEventExclusive(boolean eventExclusive)
If this property is enabled, when this component is pressed or release it won’t transmit the event to other components.
void setHandleLocation(int x, int y)
Sets the handle location of this component specified.
void setHandleLocation(Point position)
Sets the handle location of this component.
void setHeight(int height)
Changes the component height.
void setLocation(int x, int y)
Sets the location of the component.
void setLocation(Point position)
Sets the location of the component.
void setName(java.lang.String name)
Sets the name of this Component.
void setParent(Container parent)
Sets the parent of this Component.
void setRotationAngle(double angle)
Sets the rotation angle.
void setRotationCenter(double x, double y)
Sets the center of rotation.
void setScale(double scale)
Sets the horizontal and vertical scale.
void setScale(Scale scale)
Sets the scale.
void setScaleHandleEnabled(boolean scaleHandle)
Activates/deactivates the handle’s scaling feature.
void setScaleX(double scaleX)
Sets the horizontal scale.
void setScaleY(double scaleY)
Sets the vertical scale.
void setSize(int width, int height)
Changes the component’s size.
void setSurface(Surface surface)
Sets the component surface (graphical representation of the component).
void setTransparent(boolean transparent)
Sets the value which specifies if the background fill color is transparent or not.
void setVisible(boolean visible)
Sets the visibility of the component.
void setWidth(int width)
Changes the component width.
void setX(int x)
Sets the x position of the component.
void setY(int y)
Sets the y position of the component.
void toBack()
Brings to back this Component.
void toFront()
Brings to front this Component.
void update(int x, int y)
Paints the component contents.


Sent from Yahoo! Mail.
A Smarter Email.

  _____________________________________________________________________________ 

Envoyez avec Yahoo! Mail. Une boite mail plus intelligente http://mail.yahoo.fr

Oh, also…I have implemented a similar system in a game I’ve just done - a very simple approach to produce an “overlay”.
It can be visible or not, moved when visible (or not) etc etc…just as long as you update the background surface.
Quick and dirty but it works.

Here’s the code anyway. C++ isn’t my first language so don’t complain if stuff looks bad :slight_smile:

Don’t know if it’s of any use.

Header:

#ifndef IMGOverlay_included
#define IMGOverlay_included

class IMGOverlay
{
public:
IMGOverlay(int x,int y,char *filePath,SDL_Surface *srcSurface);
~IMGOverlay(); // Destructor

void UpdateBackgroundSurface(SDL_Surface *dest);
void SetAlpha(int,SDL_Surface *dest);
bool IsEnabled(void);
bool IsVisible(void);

void SetVisible(bool flag,SDL_Surface *dest);
void SetEnabled(bool flag);
void SetXY(int x,int y);
 int getX(void);
 int getY(void);

private:
bool olVisible;
bool olEnabled;
int olXPos;
int olYPos;
int olWPos;
int olHPos;
SDL_Surface *olBackSurface;
SDL_Surface *olSurface;
};

#endif

// Create an “overlay”. Ability to
// Saves portion of surface and allow replacing later
#include “stdafx.h”

#include
#include

#include “SDL.h”
#include “SDL_image.h”

#include “GfxSystem.h”
#include “IMGOverlay.h”

#include “ErrorSystem.h”

IMGOverlay::IMGOverlay(int x,int y,char *filePath,SDL_Surface *srcSurface)
{
this->olEnabled = false;
this->olVisible = false;
this->olSurface = GfxSystem::getInstance()->loadGraphic(filePath);
if (this->olSurface != NULL)
{
SDL_Rect offset;
//Give the offsets to the rectangle
offset.x = x;
offset.y = y;
offset.w = this->olSurface->w;
offset.h = this->olSurface->h;
// Grab background surface and save for restoring later
this->olBackSurface = SDL_CreateRGBSurface(SDL_HWSURFACE | SDL_SRCALPHA,this->olSurface->w,this->olSurface->h,32,RMASK,GMASK,BMASK,0);
SDL_BlitSurface(srcSurface,&offset,this->olBackSurface,NULL);
this->olHPos=this->olSurface->h;
this->olWPos=this->olSurface->w;
this->olXPos = x;
this->olYPos = y;
}
else
{
ErrorSystem::getInstance()->FatalError(ESYS_GRAPHIC_RES_ERROR,filePath);
}
}

IMGOverlay::~IMGOverlay()
{
// Free background and overlay surface
SDL_FreeSurface(this->olSurface);
SDL_FreeSurface(this->olBackSurface);
}

void IMGOverlay::SetEnabled(bool flag)
{
this->olEnabled = flag;
}

bool IMGOverlay::IsEnabled(void)
{
return this->olEnabled;
}

bool IMGOverlay::IsVisible(void)
{
return this->olVisible;
}

void IMGOverlay::SetVisible(bool flag,SDL_Surface *dest)
{
SDL_Rect offset;
//Give the offsets to the rectangle
offset.x = this->olXPos;
offset.y = this->olYPos;
offset.h = this->olHPos;
offset.w = this->olWPos;

this->olVisible = flag;

if (this->olVisible)
    SDL_BlitSurface(this->olSurface, NULL, dest, &offset );
else
    SDL_BlitSurface(this->olBackSurface, NULL, dest, &offset );

SDL_UpdateRect(dest,offset.x,offset.y,offset.w,offset.h);

}

void IMGOverlay::UpdateBackgroundSurface(SDL_Surface *dest)
{
SDL_Rect offset;
offset.x = this->olXPos;
offset.y = this->olYPos;
offset.h = this->olHPos;
offset.w = this->olWPos;
// Grab background surface and save for restoring later
SDL_BlitSurface(dest,&offset,this->olBackSurface,NULL);
}

void IMGOverlay::SetAlpha(int level,SDL_Surface *dest)
{
SDL_SetAlpha(this->olSurface,SDL_SRCALPHA|SDL_RLEACCEL,level);
SetVisible(true,dest);
}

void IMGOverlay::SetXY(int x,int y)
{
this->olXPos = x;
this->olYPos = y;
}

int IMGOverlay::getX(void)
{
return this->olXPos;
}
int IMGOverlay::getY(void)
{
return this->olYPos;
}__________________________________________________________
Sent from Yahoo! Mail.
A Smarter Email http://uk.docs.yahoo.com/nowyoucan.html

Hi Eddy,

Yes, you can compare to gimp layers, that’s completly right.
Use cases are multiples, but I’m thinking about 2D games which
are a good example of RT systems. A tile engine could easily make
use of such a system. But a GUI system too. I’ve begun a small
project, a tiny turned-based board strategy game, which will
use this.

The code you’ve written is a good simplification of what I want to do.
See the header I’ve written recently at http://code.google.com/p/sdl-layer/downloads/list
(SDL_Layer.h) to have an idea. Add to your code scrolling (viewport) with
per-layer scrolling factor, dirty rectangles, global colorkey,
visibility, color fill of each layer and you reach my goal.

As for the points you’ve mentionned:

  1. Yes, what you say is true, and I propose a viewport system to defined
    which portion of the layered display to blit on the screen, depending on
    the scrolling factor of each layer.

  2. Again, what you say is true. The first implementation will be naive.
    I imagine some optimizations will be possible. But correct me if I’m wrong,
    SDL is not designed for performance but rather for portability and clarity.
    (well, this is the way I see it).
    Extra blits are necessary if I propose such a tool. People wanting performance
    may choose to do their own layer system.

  3. Same remark as for 2.

Thank you

Julien

----- Message d’origine ----De : Edward Cullen
? : A list for developers using the SDL library. (includes SDL-announce)
Envoy? le : Samedi, 14 Juin 2008, 17h41mn 09s
Objet : Re: [SDL] Layered Display

Hi,

I’m still not exactly sure what you’re trying to achieve.

Are you trying to implement ‘layers’ as one would see them in an image
manipulation program, such as The GIMP?

What would be the use-cases for such a facility in a RT interactive system?

Your API seems to be proposing something like this:

#define LAYER_BG (0)
#define LAYER_SPRITE (1)
#define LAYER_EFFECTS (2)
#define LAYERS_TOTAL (3)

SDL_Surface* layers[LAYERS_TOTAL];

void init(void)
{
int i;
for (i = 0; i < LAYERS_TOTAL; ++i) {
layers[i] = SDL_CreateRGBSurface(disp_flags, disp_width disp_height,
… // other params as main display.
);
}
}

void draw_everything(void)
{
SDL_BlitSurface(layers[LAYER_BG], NULL, display, NULL);
SDL_BlitSurface(layers[LAYER_SPRITE], NULL, display, NULL);
SDL_BlitSurface(layers[LAYER_EFFECTS], NULL, display, NULL);
}

Here are a list of thoughts:

  1. Unless the background (BG) is actually the same size as the display
    (i.e., you aren’t using it for a larger map, with only a small part of
    it being copied), then, you’ll have to add an additional blit to setup
    the BG. It would be more optimal (performance), but more costly (RAM) to
    have a larger ‘BG layer’, with a moving window into that layer.

  2. Setting up the sprites in a separate layer just adds an additional
    blit, when you could just blit the BG into the display then blit the
    sprites in. This would save in memory bandwidth and or CPU time, as
    you’re moving less about (blitting the entire surface would involve
    alpha testing every pixel). Granted, if sprites aren’t moving, then
    you’re going to save in function call overhead, but then, sprites are
    generally supposed to be moving, so it’s doubtful whether you’d
    actually save anything…

  3. ‘Effect’ implies things that aren’t too common / have limited
    lifespan. Again, you’re probably just adding additional an additional
    blit, as in 2.

Eddy

julien CLEMENT wrote:

Hi,

Will, you might confuse me with another person, although I’ve used
IRC in the past :slight_smile:
The first goal is not really to make a parallax scrolling mechanism,
although I have mentioned it in the previous message.
The main concern is, I have a graphical application which needs
more than one display layer/plane, and there’re some sprites/animations
on those layers/planes, and of course, if something gets modified on a layer
I need to re- “project” all the other layers on the screen in the right
order for
the modified area. This is a really annoying task for a game developer I
think,
that’s why I’m proposing this tool.
Z-buffering is a technic aimed at 3D rendering: you can look at:
http://en.wikipedia.org/wiki/Z-buffer
It is something far easier I want to do, and yet maybe it can help.

Let me know, I wouldn’t begin a development without knowing if there is some
kind of interest.

By the way, thank you Edward for your message. You can help in a simple
manner:
look at the interface I’ve sent and tell me if you see missing
functionalities, and if
you imagine you can use such functions in your programs. You can mail me
directly
if you want.

Thank you guys, other comments/suggestions/ideas are welcome !

Regards

Julien


Envoy? avec Yahoo! Mail
http://us.rd.yahoo.com/mailuk/taglines/isp/control/*http://us.rd.yahoo.com/evt=52423/*http://fr.docs.yahoo.com/mail/overview/index.html.
Une boite mail plus intelligente.



SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

  _____________________________________________________________________________ 

Envoyez avec Yahoo! Mail. Une boite mail plus intelligente http://mail.yahoo.fr

Hi Julien,
I’m still SDL beginner and looking for an easy implementation of layers. But I’m not sure whether we are talking about the same thing.

I’m doing a karaoke program. Basically, I have to draw the text in realtime on the top layer and I want to have a slide show (with some effect) underneath. I wish to have something which allows me to run two threads on seperate layers and don’t have to worry re-drawing the text on the photo.

Is this what your codes support? If yes, can you give me few sample lines of code which I can start look at?

thanks
Phuoc— On Tue, 17/6/08, julien CLEMENT wrote:

From: julien CLEMENT
Subject: [SDL] Re : Layered Display
To: “A list for developers using the SDL library. (includes SDL-announce)”
Received: Tuesday, 17 June, 2008, 7:20 PM
Hi Eddy,

Yes, you can compare to gimp layers, that’s completly
right.
Use cases are multiples, but I’m thinking about 2D
games which
are a good example of RT systems. A tile engine could
easily make
use of such a system. But a GUI system too. I’ve begun
a small
project, a tiny turned-based board strategy game, which
will
use this.

The code you’ve written is a good simplification of
what I want to do.
See the header I’ve written recently at
http://code.google.com/p/sdl-layer/downloads/list
(SDL_Layer.h) to have an idea. Add to your code scrolling
(viewport) with
per-layer scrolling factor, dirty rectangles, global
colorkey,
visibility, color fill of each layer and you reach my goal.

As for the points you’ve mentionned:

  1. Yes, what you say is true, and I propose a viewport
    system to defined
    which portion of the layered display to blit on the
    screen, depending on
    the scrolling factor of each layer.

  2. Again, what you say is true. The first implementation
    will be naive.
    I imagine some optimizations will be possible. But
    correct me if I’m wrong,
    SDL is not designed for performance but rather for
    portability and clarity.
    (well, this is the way I see it).
    Extra blits are necessary if I propose such a tool.
    People wanting performance
    may choose to do their own layer system.

  3. Same remark as for 2.

Thank you

Julien

----- Message d’origine ----
De : Edward Cullen
? : A list for developers using the SDL library. (includes
SDL-announce)
Envoy? le : Samedi, 14 Juin 2008, 17h41mn 09s
Objet : Re: [SDL] Layered Display

Hi,

I’m still not exactly sure what you’re trying to
achieve.

Are you trying to implement ‘layers’ as one would
see them in an image
manipulation program, such as The GIMP?

What would be the use-cases for such a facility in a RT
interactive system?

Your API seems to be proposing something like this:

#define LAYER_BG (0)
#define LAYER_SPRITE (1)
#define LAYER_EFFECTS (2)
#define LAYERS_TOTAL (3)

SDL_Surface* layers[LAYERS_TOTAL];

void init(void)
{
int i;
for (i = 0; i < LAYERS_TOTAL; ++i) {
layers[i] = SDL_CreateRGBSurface(disp_flags,
disp_width disp_height,
… // other params as main display.
);
}
}

void draw_everything(void)
{
SDL_BlitSurface(layers[LAYER_BG], NULL, display, NULL);
SDL_BlitSurface(layers[LAYER_SPRITE], NULL, display,
NULL);
SDL_BlitSurface(layers[LAYER_EFFECTS], NULL, display,
NULL);
}

Here are a list of thoughts:

  1. Unless the background (BG) is actually the same size as
    the display
    (i.e., you aren’t using it for a larger map, with only
    a small part of
    it being copied), then, you’ll have to add an
    additional blit to setup
    the BG. It would be more optimal (performance), but more
    costly (RAM) to
    have a larger ‘BG layer’, with a moving window into
    that layer.

  2. Setting up the sprites in a separate layer just adds an
    additional
    blit, when you could just blit the BG into the display then
    blit the
    sprites in. This would save in memory bandwidth and or CPU
    time, as
    you’re moving less about (blitting the entire surface
    would involve
    alpha testing every pixel). Granted, if sprites aren’t
    moving, then
    you’re going to save in function call overhead, but
    then, sprites are
    generally supposed to be moving, so it’s doubtful
    whether you’d
    actually save anything…

  3. ‘Effect’ implies things that aren’t too
    common / have limited
    lifespan. Again, you’re probably just adding additional
    an additional
    blit, as in 2.

Eddy

julien CLEMENT wrote:

Hi,

Will, you might confuse me with another person,
although I’ve used
IRC in the past :slight_smile:
The first goal is not really to make a parallax
scrolling mechanism,
although I have mentioned it in the previous message.
The main concern is, I have a graphical application
which needs
more than one display layer/plane, and there’re
some sprites/animations
on those layers/planes, and of course, if something
gets modified on a layer
I need to re- “project” all the other layers
on the screen in the right
order for
the modified area. This is a really annoying task for
a game developer I
think,
that’s why I’m proposing this tool.
Z-buffering is a technic aimed at 3D rendering: you
can look at:
http://en.wikipedia.org/wiki/Z-buffer
It is something far easier I want to do, and yet maybe
it can help.

Let me know, I wouldn’t begin a development
without knowing if there is some
kind of interest.

By the way, thank you Edward for your message. You can
help in a simple
manner:
look at the interface I’ve sent and tell me if you
see missing
functionalities, and if
you imagine you can use such functions in your
programs. You can mail me
directly
if you want.

Thank you guys, other comments/suggestions/ideas are
welcome !

Regards

Julien


Envoy? avec Yahoo! Mail

http://us.rd.yahoo.com/mailuk/taglines/isp/control/*http://us.rd.yahoo.com/evt=52423/*http://fr.docs.yahoo.com/mail/overview/index.html.

Une boite mail plus intelligente.



SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Envoyez avec Yahoo! Mail. Une boite mail plus intelligente
http://mail.yahoo.fr_______________________________________________
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

  Get the name you always wanted with the new y7mail email address.

www.yahoo7.com.au/mail