|
Post by Pjot on Sept 24, 2015 15:27:17 GMT 1
All, Inspired by the graphical demo's at the Basic programming website, I created some functions to make fast drawings on a generic high performance OpenGL canvas. The result can be found here. Demonstration program: INCLUDE "canvas.bac"
WINDOW("Hello world", 640, 480)
' Pensize and anti-aliasing 'PEN(3, 1)
' Rotate line, circle, square ROTATION(45)
' Square INK(255,0,0,255) SQUARE(270, 130, 150, 80, 1) INK(0,0,0,255) SQUARE(270, 130, 150, 80, 0)
' Circle INK(0,255,0,255) CIRCLE(120, 120, 70, 190, TRUE) INK(0,0,0,255) CIRCLE(120, 120, 70, 190, FALSE)
' Some lines ROTATION(0) INK(0,0,255, 255) LINE(80, 30, 500, 40) LINE(500, 40, 350, 220) LINE(350, 220, 10, 250) LINE(10, 250, 80, 30)
' Triangle FOR x = 0 TO 360 STEP 10 ROTATION(x) INK(20+x, 50, 120, 255) TRIANGLE(100+x, 300, 100, 80, TRUE) INK(0,0,0,255) TRIANGLE(100+x, 300, 100, 80, FALSE) NEXT
' Paint irregular area INK(255,0,255, 255) PAINT(200, 200)
' Text INK(0,128,255,255) TEXT("Hello world! This is the High Performance Canvas based on OpenGL.", 20, 400)
' Paint rest of the screen INK(255, 255, 0, 255) PAINT(1, 1)
' Key ends WAITKEY
Enjoy, Peter
|
|
|
Post by Pjot on Sept 24, 2015 15:55:19 GMT 1
From here: INCLUDE "canvas.bac"
WINDOW("Network",640,480)
DECLARE a,x=320,y=240,r=800,c,lx,ly TYPE float
SUB Redraw FOR a=0 TO 360 STEP 0.5 INK(MOD(a,128)+127, MOD(a,128)+127, MOD(a,128)+127, 255) lx = SIN(RAD(a+c))*r ly = COS(RAD(a+c))*r CIRCLE(x,y,lx,ly,FALSE) NEXT INCR c, 0.5 IF c>=360 THEN c = -c SYNC SLEEP 10 END SUB
CALLBACK(10, Redraw) WAITKEY
|
|
|
Post by vovchik on Sept 24, 2015 22:17:41 GMT 1
Dear Peter,
Thanks for canvas.bac and the demos. I wonder how difficult it would be to use that canvas in HUG (with different keywords where they conflict - e.g. GL_CIRCLE, GL_SQUARE), so as to get GTK widgets and mouse control. And IMAGE/PICTURE with MOVE/ROTATE would be nice, too. Or a new GL_HUG.bac might be possible.
With kind regards, vovchik
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Sept 24, 2015 23:51:53 GMT 1
Cool! Much easier to do simple graphics now. And it play nicely with my simple Turtle library. INCLUDE "Lib/canvas.bac" INCLUDE "Lib/turtle.bac"
WINDOW("TEST", 900, 600) INK(255, 0, 0, 0) PEN(2, 0) RESETANGLE () GOXY (110, 300) FOR X = 1 TO 20 FORWARD (250) TURNLEFT (198) NEXT X
RESETANGLE () GOXY (230, 440) FOR K = 1 TO 10 GOX (2) GOY (2) FOR X = 1 TO 36 IF MOD (X, 2) = 0 THEN PENUP () END IF BACKWARD (20) PENDOWN () TURNRIGHT (10) NEXT X NEXT K
RESETANGLE () GOXY (350, 550) K = 2 WHILE (K < 496) FORWARD (500 - K) TURNRIGHT (91) K = K + 2 C = C + 1 WEND INK(0, 255, 0, 1) PAINT(100, 100) WAITKEY
|
|
|
Post by Pjot on Sept 25, 2015 13:29:24 GMT 1
From here: INCLUDE "canvas.bac"
WINDOW("Ears Plasma", 320, 320)
DECLARE r[256], g[256], b[256] TYPE float
DECLARE rs,c1,c2,c3,f,x,y TYPE float
FOR x=0 TO 255 r[INT(x)] = 255.0 -((SIN(3.14 * 2.0 * x / 255.0) + 1.0) * 127.0) g[INT(x)] = ((SIN(3.14 * 2.0 * x / 127.0) + 1.0) * 64.0) b[INT(x)] = 255.0 - r[INT(x)] NEXT
SUB Draw SYNC FOR y=0 TO 320 FOR x=0 TO 320 c1 = SIN(x / 50 + f + y / 200) c2 = SQR((SIN(0.8 * f) * 160-x+160) * (SIN(0.8 * f) * 160-x+160) + (COS(1.2 * f) * 100-y+100) * (COS(1.2 * f) * 100-y+100)) c2 = SIN(c2 / 50) c3 = (c1 + c2) / 2 rs = ((c3 + 1) * 127) INK(b[INT(rs)], r[INT(rs)], g[INT(rs)], 255) PIXEL(x,y) NEXT NEXT INCR f ENDSUB
CALLBACK(10, Draw) WAITKEY
|
|
|
Post by Pjot on Sept 25, 2015 13:48:54 GMT 1
Hi vovchik, The HUG context already supports GL canvas through GtkGlArea and GtkGlExt. However, these are external libraries, not by default part of GTK, and mostly need to be installed separately, provided that they are available for your platform. Also note that the implementation for Circle, Line, Text, Pixel and Square was taken from HUG anyway (no need to re-invent the wheel ). But the reason for this canvas is (1) having a small include file with (2) hardware support for drawing primitives and without (3) dependency on a large library like GTK which, in its turn, requires support of a large installbase of extra supporting libraries like Pango, ATK, GLib etc. And (4), the actual implementation of primitives can be done using OpenGL calls exclusively. Which, in case of PAINT or ROTATE, will be a lot more cumbersome in case of a GdkPixBuf based canvas. BR Peter
|
|
|
Post by vovchik on Sept 25, 2015 16:27:08 GMT 1
Dear Peter,
I had in mind a few things like this (incomplete, but working):
IMPORT "glutMouseFunc(void*)" FROM lib$ TYPE void
SUB WAITMOUSE() IF CANVAS_LIB$ = "GLUT" THEN glutMouseFunc(QUIT) glutMainLoop END IF END SUB
and something to allow for images to be placed and moved around the canvas. We could then roll our own widgets if needed. The functions all seem to be there in OpenGL, including menus. And glutMouseFunc can grab a mouse click, determine the button and store the x/y info. What do you think?
With kind regards, vovchik
|
|
|
Post by vovchik on Sept 26, 2015 8:35:34 GMT 1
Dear Peter,
The alpha in canvas.bac does not seem to be working, at least on my machine (Mint 17). We should see a difference (and transparency) in the circles here (last parameter in INK):
INCLUDE "canvas.bac" WINDOW("Alpha Test", 500, 500) INK(255, 0 ,0, 100) CIRCLE(200, 200, 300, 300, 1) INK(255, 128, 0, 200) CIRCLE(300, 300, 300, 300, 1) SYNC WAITKEY()
I looked at the enums for glutInitDisplayMode:
CONST GLUT_RGB = 0 CONST GLUT_RGBA = 0 CONST GLUT_INDEX = 1 CONST GLUT_SINGLE = 0 CONST GLUT_DOUBLE = 2 CONST GLUT_ACCUM = 4 CONST GLUT_ALPHA = 8 CONST GLUT_DEPTH = 16 CONST GLUT_STENCIL = 32 CONST GLUT_MULTISAMPLE = 128 CONST GLUT_STEREO = 256 CONST GLUT_LUMINANCE = 51
and I haven't yet found a combination that works. Any ideas?
With kind regards, vovchik
|
|
|
Post by Pjot on Sept 26, 2015 9:25:50 GMT 1
Thanks vovchik, The alpha blending was not enabled in GL, but now it is. Also I added "SCALE" Please get the latest and I hope this solves your issue. BR Peter INCLUDE "canvas.bac" WINDOW("Alpha Test", 500, 500) INK(255, 0 ,0, 100) CIRCLE(200, 200, 300, 300, 1) SCALE(1.1) INK(255, 0, 0, 200) CIRCLE(300, 300, 300, 300, 1) WAITKEY
|
|
|
Post by vovchik on Sept 26, 2015 12:09:41 GMT 1
Dear Peter,
Thanks - that solves it for alpha. For real antialiasing, I discovered that this works:
' GLUT definitions CONST GLUT_RGBA = 0x0000 CONST GLUT_DOUBLE = 0x0002 CONST GLUT_ALPHA = 0x0008 CONST GLUT_MULTISAMPLE = 0x0080 CONST GLUT_DEPTH = 0x0010 CONST GL_MULTISAMPLE = 0x809D glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_MULTISAMPLE) glEnable(GL_MULTISAMPLE)
INCLUDE "canvas.bac" WINDOW("Alpha Test", 500, 500) INK(255, 0 ,0, 100) CIRCLE(200, 200, 300, 300, 1) SCALE(1.1) INK(255, 100, 0, 200) CIRCLE(300, 300, 300, 300, 1) WAITKEY
Colors get blended nicely, and alpha works, but I still see some jaggies with straight lines in other demos. Text is fine. Again, any ideas?
With kind regards, vovchik
|
|
|
Post by Pjot on Sept 27, 2015 3:25:38 GMT 1
Hi vovchik,
The anti aliasing already works for me, without further changes.
Can you post some screenshots to demonstrate your problem?
Thanks Peter
|
|
|
Post by vovchik on Sept 27, 2015 7:16:54 GMT 1
Dear Peter, As you might be able to see from the screenshots, my little mod removes the jaggies from the blue quadrilateral. I think it looks better. I have included canvas.bac with the change and the demo prog. With kind regards, vovchik Attachments:
canvas-mod.tar.gz (6.59 KB)
|
|
|
Post by vovchik on Sept 27, 2015 12:59:48 GMT 1
Dear all, Here are two new HPC demos, taken from two of my earlier HUG progs. With kind regards, vovchik
|
|
|
Post by Pjot on Sept 28, 2015 5:13:06 GMT 1
Thanks vovchik, Your screenshots show a difference, but when running your demo on my system I really do not see any difference (and I made sure to the use framework GLUT). I have incorporated your changes ( canvas version 1.3 now) but I guess the actual result depends on the type of hardware and driver... BR Peter
|
|
|
Post by vovchik on Sept 28, 2015 11:28:58 GMT 1
Dear Peter, Thanks for the extra antialiasing - things are working fine. I now will try to do a simple mouse function if you haven't done so already. Here is a little demo culled from Tomaaz's HUG demo that works nicely with HPC and uses his turtle lib (everything is in the archive). With kind regards, vovchik UPDATE: Added a monochrome version.
|
|