Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411679 Posts in 69399 Topics- by 58453 Members - Latest Member: Arktitus

May 17, 2024, 11:13:50 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)2d vector graphics in sdl?
Pages: [1]
Print
Author Topic: 2d vector graphics in sdl?  (Read 3204 times)
dr.crow
Level 1
*



View Profile
« on: March 20, 2010, 02:04:32 AM »

I'm wondering what's the best approach to drawing vector graphics? I've been using sdl recently, and until now i've mainly used pixel graphics and pictures for my graphics, but I feel like I need something more. I would love the ability to zoom in and still have everything look great.

I've tried using the sdl_gfx library, and it works well for simple shapes. However, if I want something fancier (say alpha-gradiented circles or stuff with glowing edges) it really kills the frame rate.
What's the best approach to making vector graphics with fancy effects?

I would prefer if I could continue using sdl, but I'll switch to using opengl if it's necessary.
Logged
Core Xii
Level 10
*****


the resident dissident


View Profile WWW
« Reply #1 on: March 20, 2010, 03:22:02 AM »

There's SGE for a software rendering solution, or you could just go OpenGL for the hardware acceleration.
Logged
nikki
Level 10
*****


View Profile
« Reply #2 on: March 20, 2010, 03:51:10 AM »

or you could use cairo for vector graphics
there is some extra info on Cairo + OpenGL + SDL here (some sexy OGG movies there too! how about this for "making vector graphics with fancy effects" ?)

« Last Edit: March 20, 2010, 07:07:11 AM by nikki » Logged
dr.crow
Level 1
*



View Profile
« Reply #3 on: March 22, 2010, 10:54:21 AM »

or you could use cairo for vector graphics
there is some extra info on Cairo + OpenGL + SDL here (some sexy OGG movies there too! how about this for "making vector graphics with fancy effects" ?)
Sounds like a kick ass combo!
This is exactly what i was looking for. I'll probably just start reading opengl tutorials right away.

btw, Do you know some good tutorials on how to do 2d with opengl? Most of the tutorials i've found are oriented towards making 3d graphics, I feel like it's a waste of time reading all this stuff about 3d, when all i want to do is make 2d.
Logged
Core Xii
Level 10
*****


the resident dissident


View Profile WWW
« Reply #4 on: March 23, 2010, 10:02:34 AM »

2D in OpenGL is mostly just ignoring the 3rd dimension. You set up a specific projection (looking straight at the x-y plane, along the z axis) and then draw everything at (x, y, 0). It's "hacky" because OpenGL is principally a 3D graphics thingy, not 2D.
Logged
mjau
Level 3
***



View Profile
« Reply #5 on: March 23, 2010, 11:33:12 AM »

2D in OpenGL is mostly just ignoring the 3rd dimension. You set up a specific projection (looking straight at the x-y plane, along the z axis) and then draw everything at (x, y, 0). It's "hacky" because OpenGL is principally a 3D graphics thingy, not 2D.

OpenGL does supports 2D coordinates, so you don't have to specify the 0 if you don't want to.  Also, with an orthographic projection (glOrtho, which i think is what you mean) you don't really have to constrain yourself to the z=0 plane anyway; you could enable the depth buffer and use it for automatic layering (though you'd still have to do some manual sorting for alpha blending).
Logged
hexageek
Level 0
***



View Profile
« Reply #6 on: March 23, 2010, 11:41:52 AM »

I don't know about SDL but recently I was messing with clutter toolkit. if your only concern is desktop, for vector graphics clutter is a top notch solution: http://clutter-project.org/

beside vector graphics, it also handles windowing, input, vector animation, text and internationalization, simple gui widgets. it supports both opengl and opengl|es. it works on windows, linux and mac os.

the bad part is that it relies on some heavy LGPL libraries such as glib, gtk and pango so iphone and pretty much all consoles are out of the question.

cheers
Logged
dr.crow
Level 1
*



View Profile
« Reply #7 on: March 23, 2010, 12:50:35 PM »

I've decided to go with opengl mainly because:

* It's easy to combine with SDL (which i know pretty well).

* Fast (so far my frame rate has quadrupled compared to what i drew with SDL and sdl_gfx)

* 3D: if I want to do 3d later, it's probably nice knowing some opengl.

* Cairo/Opengl-combo seems cool.

* Cross-platform-friendly


I've started trying out some opengl. And so far i've only just created some basic shapes.

This is kind of off-topic, but i've encountered a small problem. I wrote this piece of code:
Code:
void CGfx::drawFilledPolygon(b2Vec2* vertices, int vertexCount){
    glBegin(GL_POLYGON);
        glColor3f(1.f,1.f,1.f);
        for(int i=0; i<vertexCount; i++){
            glVertex2f(vertices[i].x,vertices[i].y);
        }
    glEnd();
}
And i was convinced it would draw white polygons, but what i got was this: screenshot
Why aren't they white? Doesn't glColor3f(1.f,1.f,1.f); mean full red, green and blue?

EDIT:
Also I found some tutorials on 2d opengl/sdl:
http://basic4gl.wikispaces.com/2D+Drawing+in+OpenGL
http://gpwiki.org/index.php/SDL:Tutorials:Using_SDL_with_OpenGL
http://www.meandmark.com/opengl2dbook.html (not yet published book on 2d opengl)
« Last Edit: March 23, 2010, 12:57:59 PM by dr.crow » Logged
hexageek
Level 0
***



View Profile
« Reply #8 on: March 23, 2010, 01:31:25 PM »

btw, if you need hardware accelerated vector rendering you need cairo's glitz backend which is deprecated.
Logged
Draknek
Level 6
*


"Alan Hazelden" for short


View Profile WWW
« Reply #9 on: March 24, 2010, 04:21:24 AM »

And i was convinced it would draw white polygons, but what i got was this: screenshot
Why aren't they white? Doesn't glColor3f(1.f,1.f,1.f); mean full red, green and blue?

Probably you're still in texturing mode, so it's using the last specified texture coordinate for everything.

If that's the issue you either need to unbind the texture or disable GL_TEXTURE_2D while rendering block-colour shapes.
Logged

dr.crow
Level 1
*



View Profile
« Reply #10 on: March 25, 2010, 02:44:03 PM »

And i was convinced it would draw white polygons, but what i got was this: screenshot
Why aren't they white? Doesn't glColor3f(1.f,1.f,1.f); mean full red, green and blue?

Probably you're still in texturing mode, so it's using the last specified texture coordinate for everything.

If that's the issue you either need to unbind the texture or disable GL_TEXTURE_2D while rendering block-colour shapes.
Thanks. Unbinding the texture did the trick. Guess I just have to learn all the opengl basics.
What's the most important topics to read about when doing 2d?
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic