PDA

View Full Version : Nice looking lines [OpenGL]



arthurprs
18-07-2008, 08:31 PM
http://img381.imageshack.us/img381/1710/7e5599a583ea7fc54198d1aic7.jpg

how can i render lines like those? It's bloom or glow?

i'm trying to these effects on some weapons with that projectile

http://img291.imageshack.us/img291/7550/fx0sn3.png

User137
18-07-2008, 10:28 PM
What kind of line effect are you looking for? That image is a little too low resolution to make anything useful out and it has many different kinds of lines.

arthurprs
19-07-2008, 12:26 AM
sorry for the low res :oops: ,

I'm looking for these "nice looking lines" like on the screens above (no edges and nice colors)

high res examples, of game Grid Wars
(thumbs, click to see full image)

http://img507.imageshack.us/img507/5424/gridwars2wt1.th.jpg (http://img507.imageshack.us/img507/5424/gridwars2wt1.jpg)

http://img507.imageshack.us/img507/2167/gridwarskb8.th.jpg (http://img507.imageshack.us/img507/2167/gridwarskb8.jpg)

User137
19-07-2008, 08:38 AM
Each line there is a textured quad in my opinion. Glow in objects is rendered on top of them with a blended particle. Part of the grid in first picture may be only GL_LINES. In OpenGL there is command to make anti-aliased lines but it wouldn't cover all that graphics, besides quad may be faster to render than line.

arthurprs
19-07-2008, 06:42 PM
Each line there is a textured quad in my opinion. Glow in objects is rendered on top of them with a blended particle. Part of the grid in first picture may be only GL_LINES. In OpenGL there is command to make anti-aliased lines but it wouldn't cover all that graphics, besides quad may be faster to render than line.

can you give me more details, maybe a sample?, thanks :)

arthurprs
19-07-2008, 08:09 PM
new info found on Grid Wars gfx folder

what is the use for this?, draw the lines i think, but there is a way to draw lines using that pic?
"glow.bmp"
http://img293.imageshack.us/img293/4411/glowot6.png

the squares and other shapes it maked on PS and probably draw then with Add Blend Mode ;p
http://img186.imageshack.us/img186/5373/purplesquare1fl1.png

Brainer
19-07-2008, 08:31 PM
May be useful:
http://www.gamedev.net/community/forums/topic.asp?topic_id=377948
http://www.allegro.cc/forums/thread/592220

arthurprs
19-07-2008, 09:23 PM
May be useful:
http://www.gamedev.net/community/forums/topic.asp?topic_id=377948
http://www.allegro.cc/forums/thread/592220



For now I'm just going to use the glowing spot trick.
http://img371.imageshack.us/img371/2606/screenshot2pdwg0.th.png (http://img371.imageshack.us/my.php?image=screenshot2pdwg0.png)

but he don't say how :|

tpascal
19-07-2008, 10:46 PM
new info found on Grid Wars gfx folder

what is the use for this?, draw the lines i think, but there is a way to draw lines using that pic?
"glow.bmp"
http://img293.imageshack.us/img293/4411/glowot6.png

the squares and other shapes it maked on PS and probably draw then with Add Blend Mode ;p
http://img186.imageshack.us/img186/5373/purplesquare1fl1.png

What seems you are looking for is called "particle system", litle rectangles with textures like in your example glow.bmp and rendered with blended and additive atributes; it is used for a produce a lot different effects like flames, explosions, ray guns shots, snow, etc.

arthurprs
22-07-2008, 11:02 PM
and the lines :? ?

User137
23-07-2008, 12:04 PM
Like this site said:
http://www.allegro.cc/forums/thread/592220
It looks like this http://i35.tinypic.com/1zcfleb.png

And a quad with texture (also shown in next screenshot only scaled up from 4x4 used in test). This line does also scale well and remain smooth, as it is loaded with GL_LINEAR filter.
Looks like http://i38.tinypic.com/fjoler.png

arthurprs
24-07-2008, 02:23 AM
thanks :D

arthurprs
25-07-2008, 06:00 PM
i'm having some problems here,

zoomed texture, the original is 4x4px
http://img155.imageshack.us/img155/7251/brush2wc1.jpg


and how it looks when i draw stretched
http://img244.imageshack.us/img244/3050/clipboard01vr0.png

filters used:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

waran
25-07-2008, 06:31 PM
And where is your Problem?

It does what it says - it filters GL_LINEAR. Means in this case a
smooth line from black to white to black.

If you want a hard cut you should use GL_NEAREST.

arthurprs
25-07-2008, 07:13 PM
And where is your Problem?

It does what it says - it filters GL_LINEAR. Means in this case a
smooth line from black to white to black.

If you want a hard cut you should use GL_NEAREST.

look the results of user137, and he used GL_LINEAR

http://i38.tinypic.com/fjoler.png

GL_NEAREST really solved the problem

JSoftware
25-07-2008, 08:29 PM
Try clamp_to_edge or clamp as wrap mode

User137
25-07-2008, 08:40 PM
If you use GL_NEAREST you lose all the details from the texture itself and effects you can achieve with it.

It's in your texture coordinates. I didn't use full area of the texture but a slice through the middle, that way the end points don't go as smooth. To make end points smooth requires quads also to the end points.

This would be the exact same to use a 1 dimensional texture 4x1 0,255,255,0 but my engine isn't supporting them yet.

This is the exact code used, not very optimal but works...:
glLoadIdentity;
glTranslatef(0,0,-5);
glSetTex(dotTex);
glTranslatef(-2,-1,0);
glRotatef(angle(-2,-1,2,1),0,0,1);
d:=hypot(4,2);
glScalef(d,d,1);
d:=0.01;
glBegin(GL_QUADS);
glColor3f(1,0.5,0.2);
glTexCoord2f(0.0,0.5); glVertex2f(0, d);
glTexCoord2f(1.0,0.5); glVertex2f(0, -d);
glTexCoord2f(1.0,0.5); glVertex2f(1, -d);
glTexCoord2f(0.0,0.5); glVertex2f(1, d);
glEnd;

When i render that with d:=0.1 i get these (added together with msPaint):
http://i37.tinypic.com/2numz2g.png

arthurprs
26-07-2008, 07:09 PM
i'm trying something more simple (not rotated), but i could not get that "gradient effect" on the sides of the line

glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.5); glVertex2f(100, 4);
glTexCoord2f(1.0, 0.5); glVertex2f(300, 4);
glTexCoord2f(1.0, 0.5); glVertex2f(300, 14);
glTexCoord2f(0.0, 0.5); glVertex2f(100, 14);
glEnd();

User137
26-07-2008, 08:51 PM
Maybe this?
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.5); glVertex2f(100, 14);
glTexCoord2f(1.0, 0.5); glVertex2f(100, 4);
glTexCoord2f(1.0, 0.5); glVertex2f(300, 4);
glTexCoord2f(0.0, 0.5); glVertex2f(300, 14);
glEnd();

arthurprs
26-07-2008, 09:16 PM
Maybe this?
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.5); glVertex2f(100, 14);
glTexCoord2f(1.0, 0.5); glVertex2f(100, 4);
glTexCoord2f(1.0, 0.5); glVertex2f(300, 4);
glTexCoord2f(0.0, 0.5); glVertex2f(300, 14);
glEnd();

same :\

zoomed texture, the original is 4x4px
http://img155.imageshack.us/img155/7251/brush2wc1.jpg

mag and min filters set to GL_LINEAR

User137
27-07-2008, 09:05 AM
mag and min filters set to GL_LINEAR
... after glBindTexture on the specific texture? :)

arthurprs
27-07-2008, 08:45 PM
mag and min filters set to GL_LINEAR
... after glBindTexture on the specific texture? :)

yes

i have tried rendering with trianglestrip, same result =\

Andreaz
28-07-2008, 09:04 AM
Try this version, use the same texture as you posted before, it renders 3 quads, uses some vector math to avoid messing with rotations.



Procedure DrawLine(const PStart: TVector2f; const PEnd: TVector2f; Width: Single);
var Vector : TVector2f;
var Normal : TVector2f;
var NXW: Single;
var NYW: Single;
var VXW: Single;
var VYW: Single;
begin
Vector.X:= PEnd.X - PStart.X;
Vector.Y:= PEnd.Y - PStart.Y;

Vector:= Normalize(Vector);

// Calculate the normal to the vector
Normal.X:= -Vector.Y;
Normal.Y:= Vector.X;

// Precompute the factors
NXW:= Normal.X * Width;
NYW:= Normal.Y * Width;

VXW:= Vector.X * Width;
VYW:= Vector.Y * Width;

glEnable(GL_TEXTURE_2D);

glBegin(GL_QUADS);
// First quad
glTexCoord2f(0.0, 0.5); glVertex2f(PStart.X - NXW + VYW, PStart.Y - NYW + VYW);
glTexCoord2f(1.0, 0.5); glVertex2f(PStart.X + NXW + VYW, PStart.Y + NYW + VYW);
glTexCoord2f(1.0, 0.5); glVertex2f(PEnd.X + NXW - VYW, PEnd.Y + NYW - VYW);
glTexCoord2f(0.0, 0.5); glVertex2f(PEnd.X - NXW - VYW, PEnd.Y - NYW - VYW);

// Middle quad
glTexCoord2f(0.0, 0.0); glVertex2f(PStart.X - NXW , PStart.Y - NYW);
glTexCoord2f(1.0, 0.0); glVertex2f(PStart.X + NXW , PStart.Y + NYW);
glTexCoord2f(1.0, 0.5); glVertex2f(PStart.X + NXW + VXW, PStart.Y + NYW + VYW);
glTexCoord2f(0.0, 0.5); glVertex2f(PStart.X - NXW + VXW, PStart.Y - NYW + VYW);

// End quad
glTexCoord2f(0.0, 0.0); glVertex2f(PEnd.X - NXW , PEnd.Y - NYW);
glTexCoord2f(1.0, 0.0); glVertex2f(PEnd.X + NXW , PEnd.Y + NYW);
glTexCoord2f(1.0, 0.5); glVertex2f(PEnd.X + NXW - VXW, PEnd.Y + NYW - VYW);
glTexCoord2f(0.0, 0.5); glVertex2f(PEnd.X - NXW - VXW, PEnd.Y - NYW - VYW);
glEnd();
end;

arthurprs
28-07-2008, 06:03 PM
the result andreaz
http://img174.imageshack.us/img174/5264/clipboard012eu9.png

User137
28-07-2008, 06:20 PM
and how it looks when i draw stretched
http://img244.imageshack.us/img244/3050/clipboard01vr0.png
I don't understand, i can clearly see you have LINEAR working in that screenshot, yet it stopped working?

arthurprs
28-07-2008, 08:34 PM
EDIT: forget about the errors, the code is working perfectly, the #@!@# here forgot that he changed the texture...

Andreaz
29-07-2008, 08:01 AM
the result andreaz
...snip...

It should really look like this,
http://phoenixlib.net/files/Screen0.png

Well here's the complete source
http://phoenixlib.net/files/Nice_looking_lines.zip

arthurprs
29-07-2008, 05:27 PM
Thanks Andreaz, the code works good

changing topic,

I was looking on phoenixlib sources and i noticed that you use display lists and vertexarray on particles, those method are really faster?

Andreaz
30-07-2008, 07:52 AM
Yeah, vertex arrays is alot faster then intermediate mode (glBegin, glVertex, glEnd).

And displaylists can be faster then vertex arrays, atleast for static geometry. However displaylists is a tricky subject, they might be implemented in the driver and not in the gpu.

In the new version of Phoenix i'm going away from displaylists and using vertex arrays and vertex buffer objects instead.