PDA

View Full Version : Vector Graphics



Pipes
29-08-2009, 16:24
Hi tB users,

Is it possible to draw vector graphics with OpenGL. By that, I mean graphic primitives like simple lines, rectangles, ellipses, circles etc.
onto a 3D surface. (2D primitives on top of a 3D surface) I don't know much about OpenGL capabilities. So before I scour the docs, I was hoping to get a quick answer. Perhaps one has to use windows GDI. If so, can the GDI be drawn on top of a OpenGL surface.? Perhaps someone can point me in the right direction.

Thanks

May all your thinBasic endeavors be successful.

Charles Pegge
29-08-2009, 17:35
Hi Pipes,

Kent Sarikaya's Tank Wars Game is rich in TBGL Line Graphics and several other goodies.


http://community.thinbasic.com/index.php?topic=1798

Charles

Michael Hartlef
29-08-2009, 17:52
TBGL supports some 2D primitives. Rect, circle, line. Let me know if that's what you need.

ErosOlmi
29-08-2009, 19:32
Pipes,

to have the latest 2D primitive developed by Michael Hartlef and Petr Schreiber be sure to install one of the latest thinBasic beta versions. You can download them from http://community.thinbasic.com/index.php?board=176.0
They recently did a great development stage in the 2D world.

Eros

Pipes
30-08-2009, 14:48
Hi Michael,


TBGL supports some 2D primitives. Rect, circle, line. Let me know if that's what you need.

Are these 3D objects or 2D primitives? By 3D objects, I mean polygons that have been created in 3D space then colored or textured.
I want to create an image, (bmp,jpg,png etc.) draw lines, rectangles, circles etc. to it, then overlay it on a 3D scene. Much like Blitz3D if you are familiar with that language. I'm not sure TBGL or OpenGL will do that. I think with the allegro graphics library that can be used with OpenGL doesn't exactly accomplish that task either. At least not without jumping through some hoops. So I'm not sure if it can be done in OpenGL or TBGL. Presently, I'm in information overload. Simple answers just don't compute in the information age. Documentation can be overwhelming in any library or programming language. Does not compute... Does not compute... Does not compute... Does not compute... Does not compute... Warning info overload... Does not compute... Does not compute... Warning out of memory.... :violent:

Sorry I got stuck in a recursion descent.

Thanks

Petr Schreiber
30-08-2009, 15:02
Hi Pipes,

once you get out of that recursion :) - yes, you can render in 3D and 2D mode and combine it to one image.
What is your planned project about?

Pipes
30-08-2009, 16:17
Hi Petr,


What is your planned project about?

All righty then... Forever and a day I've been working on a Game users interface for Blitz3D (Well okay that's a bit dramatic). Off and on for quite awhile, I've been working on a Game user interface for Blitz3D. Complete with all the normal user controls one would find in a windows environment (not to be confused with actual windows controls but essentially acts like windows) and then some. Included are scrollable or non-scrollable type image thumbnails much like an inventory system in an RPG but user designated. User designated window skins, borders, headers and footers etc.
In my opinion Blitz3D is fading in the sunset stuck in old technology like directX7 with no changes coming in the future. Most users have switched to BlitzMax. That's another subject sore entirely. I thought about changing the GUI to thinBasic to be used with TGBL to share with the community. I know you can use windows controls with TGBL, but windows controls look like application controls not game controls. I've worked too long on the project just to let it fade in the sunset. Many of the procedures and functions would easily port to thinBasic so I'm exploring other avenues. (By now you're probably sorry you asked. :D) That about sums it up.

May all your thinBasic endeavors be successful,

Pipes

Michael Hartlef
30-08-2009, 18:33
:eusadance: What, did I gear GUI?? Is my dream comming true? Let me know what you need and I will try to help whatever you need. You were asking about if the 2D primitives are 3D or 2D. OpenGL is all 3D, for these 2D functionalities liek the primitives or the sprites, you switch to a different coordinate system and make it a orthographic viev. 2D and 3D can be easily mixed. It is just a matter of state changing.

Man, I would love to have a skinnable gui system for TBGL.

Btw. I didn't know you were a blitzer. How small the world is. TBGL entity system was motivated by the Blitz entity system.

Petr Schreiber
30-08-2009, 18:39
Hi Pipes,

that sounds interesting, do you have any screenshots?!

Pipes
30-08-2009, 21:21
Hi Michael,

Yes, I'm a blitzer for many years. I still like it but I think that boat is sailing away. Do you still use it? It's hard to give it up. My passion has always been game programming. I think game programmers should be writing games not designing a user interface. However, blitz was sadly lacking in that area for my taste. So I re-invented the wheel. Now, I'm really into it. :shock:

Petr, here are a couple of screens from blitz. Keep in mind this is not a finished product nor are all the features shown but it's a start.

May all your thinBasic endeavors be successful...

Pipes

Michael Hartlef
30-08-2009, 22:08
:shock: WOW, it looks just what I was dreaming about.

Ok Pipes, now you are officially our gui developer. Joke aside, I hope you will bring this baby to TBGL, because that is something we are missing. A nice gui lib. Great job. Can you post the skin file so I can see how this was organized?

Petr Schreiber
30-08-2009, 22:09
Whoa!

That looks pretty good Pipes!

Pipes
30-08-2009, 23:39
Hey,

Thanks guys. Here are the skins that I constructed the windows, borders, headers with. 1st two are header files with a color key to tell the program what colors to use on the windows. The next two are custom border files. The final two are the bmpFonts for the controls. The user can designate custom headers, borders or bmpFonts or use default settings for plain windows, controls and tt fonts. The rest is just vector or primitive graphics drawn with different functions. I will give it the ole college try to transfer to TBGL. I'm sure I'll have questions for this endeavor. TBGL is a lot different than Blitz. (It is about the passion :excited:)

Pipes
31-08-2009, 01:57
Hey,

After some research this afternoon, I see there will be more than a few problems with this whole endeavor to port the GUI from Blitz to TBGL. There just doesn't seem to be any 2D handling capabilities in OpenGL, TBGL (Other than sprites and textures) or thinBasic. At the minimum the following functions would be required:

handle = LoadImage(Filename) ---Load png,jpg,bmp etc.
handle = CopyImage(handle) ---Copy one image to another
handle = CreateImage(width,height,frames) ---Create images on the fly
handle = LoadAnimImage(filename,width,height,first,count) ---Load and animation image sequence
handle = GrabImage(image,x,y,frame) --- Grab an image or a portion of an image
DrawImage(handle, x,y,frame) --- Darw an image to the current image buffer (Screen or back buffer)
DrawImageRect(handle,x,y,rect_x,rect_y,rect_width,rect_height,frame) ---Draw a portion of an image to another image
FreeImage(handle) ---Free an image from memory
TileImage(handle,x,y,frames) ---Tile an image to another
MaskImage(handle,red,green,blue) ---Set image transparency
ResizeImage(handle,width#,height#) ---Resize image
ScaleImage(handle,xscale#,yscale#) ---Scale by percentage
RotateImage(handle,value#) ---Rotate image
int = ImageWidth(handle) ---Get image width
int = ImageHeight(handle) ---Get image height
SetBuffer buffer ---Set current drawing buffer
LockBuffer buffer ---Lock current buffer for fast drawing
UnlockBuffer buffer ---Unlock current buffer for normal drawing operations
buffer = ImageBuffer(handle,frame) ---Get an image buffer
buffer = FrontBuffer() ---Get the front buffer
buffer = BackBuffer() ---Get the backbuffer
PutPixel(buffer)
GetPixel(buffer)
GetPixelColor(buffer, x, y)
blit(src_x,src_y,src_width,src_height,dest_x,dest_y,src_buffer,dest_buffer)
CopyRect(src_x,src_y,src_width,src_height,dest_x,dest_y,src_buffer,dest_buffer)
SetColor(red,green,blue)
ClsColor(red,green,blue)
Line x1,y1,x2,y2
Rect x, y, width, height, solid = (True/False)
Oval x,y,width,height,solid = (True/False)
Circle x,y,width,height,solid = (True/False)

These are all extensive 2D image routines. Does thinBasic or TBGL have any of these capabilities? :read:

Hey Michael, do you recognize some of these functions from Blitz3D. (See why I like it) DirectX7 was the bomb for handling 2D and plastering images all over 3D graphics scenes and Blitz wrapped all that up in a nice layer that hid the mess from the average user. :)

May all your thinBasic endeavors be successful,

Pipes

Charles Pegge
31-08-2009, 05:10
Hi Pipes,

I'll leave it to the experts but it seems to me that these classic basic functions could all be emulated with TBGL/Opengl. The pixel operations, for instance closely relate to texture mapping onto a flat surface and if necessary, Opengl will also allow you to handle individual pixels in the projected image.

Charles.

Michael Hartlef
31-08-2009, 06:05
Hi pipes
Yes i know them. And will try to replicate them if you like.

Michael

Petr Schreiber
31-08-2009, 09:04
Hi Pipes,

as guys said - there are equivalents of those functions in TB. They do not have same names, but they are here.
The command you listed (considering I do not know Blitz) show approach similar to one used in GDI.
As Charles said, OpenGL rather than manipulating images renders polygons with images mapped. This way is much more efficient for hardware and is adopted by most game developers*.

One thing you should know - TBGL supports BMP and TGA file formats at the moment. PNG, JPG will follow once ThinBASIC 2.x is out.

The reason is that OpenGL does not provide any image handling routines, it only accepts raw buffers of RGB(A) components. So adding support for JPG and PNG would mean bloating the TBGL with loading code for these formats.
Once ThinBASIC 2.x (WinXP+) is out, I can rely on fact GDIPlus library is always present, so I can take advantage of its image format magic.


Petr

* Yes, there are functions like glDrawPixels in OpenGL, but I never used them as they seem little inefficient to me.

Michael Hartlef
31-08-2009, 12:20
Hi pipes
Yes i know them. And will try to replicate them if you like.

Michael




Ok, then it is maybe better to wait till then.

Petr Schreiber
31-08-2009, 14:28
Pipes,

could you tell us how is your GUI library designed from function calls point of view (not implementation, just the function names and parameters)?

Thanks

Pipes
31-08-2009, 14:57
Hi Charles,


I'll leave it to the experts but it seems to me that these classic basic functions could all be emulated with TBGL/Opengl.

I'm sure you are right. There's always more than one way to climb a mountain. It will require more investigation on my part. I have to rely on the experts to point me in the right direction. I'm certainly not one myself. I've always been a BASIC programmer from the old school. The more layers I have between me and some of these complex libraries, the better I like it. (DirectX, OpenGL, Windows API)

Hi Michael,


Yes i know them. And will try to replicate them if you like. Ok, then it is maybe better to wait till then.

Yes, I would like it, but it would probably be a lot of work. Seems that a module for handling 2D graphics would be beneficial. I just don't know how to go about it myself.


Hi Petr,


The command you listed (considering I do not know Blitz) show approach similar to one used in GDI.

Yes, I believe I mentioned GDI in one of the above post. Although, I don't like GDI much. It has some similar functions. That seems like going backwards to me for some reason.


OpenGL rather than manipulating images renders polygons with images mapped. This way is much more efficient for hardware and is adopted by most game developers*.

I'm sure you are right. You are the OpenGL pro in my opinion. I understand the concept but how to apply it will require more effort on my part. I have worked with DirectX before and way back in DX7 the capabilities were there for great 2D handling. Microsoft changed it in DX8 similar to OpenGL. Whether or not it bloated the library is a matter of debate. The industry direction went towards 3D so it only makes sense the libraries would change. That may be the other way around. The libraries went towards 3D so the industry followed. (Who knows?) However, I liked the 2D capabilities (or at least the way it was handled) and I still do. It probably is more efficient for hardware and you are correct. Most professional game programmers have gone the way the 3rd dimension. I'm an old school amateur and perhaps a little strange. I seem to think programming is interesting, fun and my favorite pass time. (It's the passion as I've heard many times around thinBasic :excited:)


The reason is that OpenGL does not provide any image handling routines, it only accepts raw buffers of RGB(A) components.

Okay... I admit I don't know what that means, The rgb and alpha component rings a bell but the raw buffer thing draws a blank in my mind. (Hardware memory?)

Oh well... I will endeavor to persevere and may all your programming endeavors be successful.

Pipes

Petr Schreiber
31-08-2009, 17:04
Hi Pipes,

thanks for you comments. Maybe I expressed wrongly ... I am 100% sure it is possible to recreate your GUI lib in ThinBASIC, I just wanted to show the same goals ( drawing images on screen ) can be achieved via multiple ways, and TBGL does it the polygon way :) You can scale, translate, flip, repeat images for sure, and I think it is not that difficult to do. Some examples are located in SampleScripts/TBGL.

The bloating was mentioned in sense "making DLL size grow too much". I am all for having PNG and JPG support, just found it little redundant to do it myself when GDIPlus does provide it already. You can already use any 3rd part library to load image and TBGL_MakeTexture to make it "TBGL compatible".

With my confusing speech on RGB(A) I wanted to say, that the image loading I do myself, and internally I pass to OpenGL only the RGBARGBARGBA... sequence. That means adding PNG loader would mean some extra work for me (the specification is quite brutal). Once ThinBASIC moves XP only way, I can drop the code for BMP and TGA loading from TBGL, and replace it with system present GDIPlus image format routines. I dislike dependancy libs, that is why TBGL currently (supporting Win95 - Win7) does not use freeImage or DevIL. Once we will move WinXP+ way, I can rely on fact GDIPlus will be always there.

I hope it is more clear now :)


Petr

Pipes
31-08-2009, 20:44
Hi Petr,

Yes, that is more clear. Use GDI+ for image manipulation and convert images into sprites or polys to display in TBGL. Correct?


could you tell us how is your GUI library designed from function calls point of view (not implementation, just the function names and parameters)?

These are some of the external functions exposed to the user. The internal functions are quite extensive and a pain to list but maybe this will give you some idea. I didn't list the return type, most are standard data types some are UDTs. This list is not comprehensive because I still have some controls to add and procedures to complete.



Window/Control manipulation

pui_change_default_color(hr,hg,hb,sr,sg,sb,br,bg,bb,tr,tg,tb)
pui_change_hilite_color(r,g,b)
pui_change_shadow_color(r,g,b)
pui_change_backgrnd_color(r,g,b)
pui_change_text_color(r,g,b)
pui_append_list(hWnd,hcontrol,txt$)
pui_free_gui()
pui_file_request$(dir$,filter$,cap$)
pui_get_val(hcontrol)
pui_get_winwidth(hWnd)
pui_get_winheight(hWnd)
pui_get_winx(hWnd)
pui_get_winy(hWnd)
pui_hide_win(hWnd)
pui_lock_all_win()
pui_lock_win(hWnd)
pui_lock_control(hcontrol)
pui_set_helptext(hcontrol,help$)
pui_set_imbox_color(hWnd,hcontrol,cr,cg,cb)
pui_set_screen(mode,size,file$,pw,ph,frst,frames,scrn,gbr,gbg,gbb)
pui_set_val(hWnd,hcontrol,t$)
pui_set_helptext(hcontrol,help$)
pui_set_winfocus(hWnd)
pui_show_win(hWnd)
pui_msg_box(cap$,msg$,n)
pui_toggle_popups()
pui_unlock_all_win()
pui_unlock_win(hWnd)
pui_unlock_control(hcontrol)
pui_update_progress(hcontrol,f#)
pui_user_input$()
pui_win_visable(hWnd)

Window Creation:

To crerate a window you must pass the following structures (udts) to pui_create_window()

myflags.pi_flags = PUI_set_winflags(visible,tilebg,border,header,footer,f_text,f_time,movebtn,minmaxbtn,resizebtn,closebtn,helpbtn,retain )
mycolors.pi_colors = PUI_set_wincolors.pi_colors( hr,hg,hb,sr,sg,sb,br,bg,bb,tr,tg,tb,mr,mg,mb )
myheader.pi_header = PUI_set_winheader(caption$, icon$, txstyle, imfile$, font$, fsize, imfont$="" )
myfooter.pi_footer = pui_set_winfooter(txt$="",font$="",fsize=0,txstyle=0,imfont$="")
myborder.pi_border = pui_set_winborder.pi_border(file$)

hWnd = pui_create_window(x,y,w,h,bgimfile$,style,myflags,mycolors,myheader,myfooter,myborder)

Control creation :

hcontrol=pui_create_button(hWnd,x,y,w,h,file$,txt$,style,f_lock,f_resize,help$)
hcontrol=pui_create_cyclebtn(hWnd,x,y,w,FontHeight()*n,txt$,style,f_lock,help$)
hcontrol=pui_create_floatbox(hWnd,x,y,w,h,txt$,style,txtpos,finc#,min$,max$,dfault$,f_lock,help$)
hcontrol=pui_create_frame(hWnd,x,y,w,h,txt$,style,f_resize)
hcontrol=pui_create_horzslider(hWnd,x,y,w,h,txt$,style,txtpos,inc,min$,max$,f_lock,help$)
hcontrol=pui_create_imagebox(hWnd,x,y,w,h,file$,txt$,mr,mg,mb,style,resize,txtpos,f_masked,help$)
hcontrol=pui_create_inputbox(hWnd,x,y,w,h,txt$,style,txtpos,dfault$,f_lock,help$)
hcontrol=pui_create_integerbox(hWnd,x,y,w,h,txt$,style,txtpos,inc,min$,max$,dfault$,f_lock,help$)
hcontrol=pui_create_label(hWnd,x,y,w,h,txt$,style,f_resize,f_lock,help$)
hcontrol=pui_create_listbox(hWnd,x,y,w,h,txt$,txtpos,list$,f_lock,help$)
hcontrol=pui_create_menu(hWnd,x,y,w,h,txt$,help$)
hcontrol=pui_create_textbox(hWnd,x,y,w,h,txt$,txtpos,f_lock,help$)
hcontrol=pui_create_toggle(hWnd,x,y,imfile$,txt$,style,f_check,txtpos,f_lock,help$)
hcontrol=pui_create_vertslider(hWnd,x,y,w,h,txt$,style,txtpos,inc,min$,max$,f_lock,help$)

Somewhere in your game loop place this line of code :

If pui_process_event() Then Gosub Check_Controls ---Event_Procedure (Message Handler) is setup by user (can be function or sub)

Returns True For Event

mouse button down
double click
key press
etc.

When an event occurs a global internal struct is filled with the appropriate info
window handle
control handle
mouse position
key info
etc.


I couldn't resist with the PUI. Hey that stands for for Pipe's User Interface not poo-ie. :yahoo:

Pipes