Archived

This topic is now archived and is closed to further replies.

Ninkazu

Crossfading screens...

Recommended Posts

I''m still a n00b to OpenGL, but I can''t find any resources on this. Say I have two bitmaps, both 640*480. Is there a way to make a nice clean transition from one to the other? I was thinking I would have to shrink them to 256*256 and just decrease alpha while increasing the other''s. I downloaded NVidia''s crossfade thing, but it''s kind of a dissolve thing I don''t want to do. Thanks.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
i don''t see why you''d need to change both alpha''s, you''d only need to change the alpha of the bitmap being drawn on top surely.

Share this post


Link to post
Share on other sites
If you want to fade the bitmaps on screen never beats OpenGL (or in general 3DHW)...simply draw overlapped bitmaps as textured quads (in Ortho2D for example).
For the first texture disable BLEND, for the second one enable BLEND and use MODULATE texture parameter with modulating color 1,1,1,alpha where alpha goes from 0.0f to 1.0f.

Or do you want to fade via software? In this case you have to implement your own ALPHABLEND function.
It is simply

c = c1*(1-alpha) + c2*(alpha) alpha=0.0,...,1.0

where c is a component (R,G or B)...

A realistic code dont use floats! So you should use look up tables : are you interested about this?

Share this post


Link to post
Share on other sites
Ok, its very simple.
I think that you already know how to draw a BMP on your screen using GL_QUAD.

So, simply do it like that :


  

glEnable(GL_TEXTURE_2D);
DrawImage2();
glDisable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ONE);
// Fade white to black

glColor4f(Transition,Transition,Transition,1);
//...draw a quad here the size of the screen. (no tex)

glBlendFunc(GL_ONE,GL_ONE);
glEnable(GL_TEXTURE_2D);
DrawImage1();
glDisable(GL_BLEND);

Share this post


Link to post
Share on other sites
hum... you really dont know OpenGl...

First, 640x480 its not a good idea for a texture.
Because old card, like Voodoo or Ati 32Mo, support max 512x512 textures.
And only square of 2.
16,32,64,128,256,512
so you can make texture like : 64x64 , 256x16, shit like that.
So use a image editor, like Photoshop, to resize your 640x480 texture to 512x512.
After you load your BMP in opengl. Do you know how to create texture in Ogl?????? if not, go to see tutorial on ogl first. Because this post will take 5 pages to explain all you want to do.

good site to learn it : Nehe productions
Learn all about ogl in it.
But what you only have to learn (for your need) its texture loading. And probably create an opengl window.

Share this post


Link to post
Share on other sites
I''ve read many of the NeHe tutorials, but they just haven''t sunk in yet. The thing I just want to ask is.... I can''t have a fullscreen picture? It doesn''t have to be a texture, but just... a picture.

Share this post


Link to post
Share on other sites
Rendering plain images in OpenGL is possible, but its usually slow. Textured quads are generally much faster. Your best bet, if you want to avoid complication, is to create a 1024x512 texture and only use the bottom left 640x480 pixels when you render the quad. All decent graphics cards support texture sizes up to 2048x2048 anyway

[edited by - benjamin bunny on May 3, 2003 10:51:56 PM]

Share this post


Link to post
Share on other sites
OpenGL is ***VERY*** simple.
The only thing harder its to initiate all the shit. Like OpenGL windows, pixel format, loading texture fonction. After that, its very simple to make all effects you want. After that your crossfade will be easy to make. ogl is the simples way to make the effect you want. DirectX is more complicated and in software probably very hard and very slow.

Share this post


Link to post
Share on other sites
DirectX in software is actaully better than OpenGL in software under Windows. As far as harder in software, there really is no difference in the code as far as I know.

Another way to handle a 640x480 image is to break to up into mipmaps. I can''t give you specifics on this, and since you seem to be rather new it would probably be best to just use a power of 2 texture bigger than what you need.

If you intrested in the mipmap solution though, I''m sure somebody on this forum can explain it much better than I could.

Share this post


Link to post
Share on other sites
Alpha blending in software is one of the simplest thing to do: there are a lot of java demos that use alpha blend via software and they run at a decent speed...in C (and _asm) the things go better of course (I''ve tried both)!
To get an idea, an alpha blend with RGBA 256x256 images will take no more than 2-4 ms to be rendered (in good code). So it is not fast as a 3D HW but not so slow!

We know that DX goes faster than OpenGL in software...the difference is that OpenGL is a graphic library
However, in pure software, D3D/OpenGL are too slow to be used as a 2D renderer(perform a lot of mults and divisions to draw a bitmap is not wise).
DirectDraw is simply a set of ''memcopy'' functions and if you want to do a serious 2D effect you must implement it by yourself.


To Ninkazu: if you want to perform a fast alpha blending on screen between two images and you are sure to use 3DHW use OpenGL (simple&fast solution).

Share this post


Link to post
Share on other sites