|
Post by Ben on Dec 9, 2016 18:53:52 GMT
I can't find any information on drawing things like circles, boxes, etc. Am I living too far in the past?
|
|
|
Post by Tom on Dec 14, 2016 10:05:34 GMT
Actually that's a good question. Right now there aren't any. Perhaps I should add some.
In the meantime you can fake it to some extent using sprites. I had a little go and came up with this:
' Drawing textures dim circleTex = LoadTex("gfx/circle.png") dim squareTex = LoadTex("gfx/fullsquare.png")
' Drawing state ' Change these to change the drawing dim penColor(2) as single = vec3(255, 255, 255) dim penWidth as single = 1 dim penPos(1) as single
' Drawing routines. ' Each come in 2 versions. One taking a vector
' Draw a line sub DrawLineVec(p1() as single, p2() as single)
' This creates a rectangular sprite, with one end at p1, then stretches it out and rotates it ' so that the other end reaches p2. dim dif(1) as single = p2 - p1 dim l as single = length(dif) if l < 0.0001 then return endif NewSprite(squareTex) SprSetPersistent(false) ' Non persistent sprites are deleted immediately after DrawText() is called SprSetColor(penColor) SprSetYCentre(0) SprSetPos(p1) SprSetSize(penWidth, l) SprSetAngle(-atn2d(dif(0), dif(1))) end sub
sub DrawLine(x1 as single, y1 as single, x2 as single, y2 as single) DrawLineVec(vec2(x1, y1), vec2(x2, y2)) end sub
' Move the pen to a position sub MoveToVec(p() as single) penPos = p end sub
sub MoveTo(x as single, y as single) MoveToVec(vec2(x, y)) end sub
' Draw a line from the pen's position to the new position (and move the pen) sub LineToVec(p() as single) DrawLineVec(penPos, p) MoveToVec(p) end sub
sub LineTo(x as single, y as single) LineToVec(vec2(x, y)) end sub
' Draw a rectangle sub DrawRectVec(pos() as single, size() as single) dim savePenPos(1) as single = penPos MoveToVec(pos) LineToVec(pos + vec2(size(0), 0)) LineToVec(pos + size) LineToVec(pos + vec2(0, size(1))) LineToVec(pos) penPos = savePenPos end sub
sub DrawRect(x as single, y as single, width as single, height as single) DrawRectVec(vec2(x, y), vec2(width, height)) end sub
' Draw a square sub DrawSquareVec(pos() as single, size as single) DrawRectVec(pos, vec2(size, size)) end sub
sub DrawSquare(x as single, y as single, size as single) DrawSquareVec(vec2(x, y), size) end sub
' Draw an oval sub DrawOvalVec(center() as single, width as single, height as single) dim savePenPos(1) as single = penPos MoveToVec(center + vec2(0, height / 2)) dim i for i = 10 to 360 step 10 LineToVec(center + vec2(sind(i) * width / 2, cosd(i) * height / 2)) next penPos = savePenPos end sub
sub DrawOval(x as single, y as single, width as single, height as single) DrawOvalVec(vec2(x, y), width, height) end sub
' Draw a circle sub DrawCircleVec(center() as single, radius as single) DrawOvalVec(center, radius * 2, radius * 2) end sub
sub DrawCircle(x as single, y as single, radius as single) DrawCircleVec(vec2(x, y), radius) end sub
' Draw a filled in rectangle sub FillRectVec(pos() as single, size() as single) NewSprite(squareTex) SprSetPersistent(false) SprSetColor(penColor) SprSetPos(pos) SprSetSize(size) SprSetXCentre(0): SprSetYCentre(0) end sub
sub FillRect(x as single, y as single, width as single, height as single) FillRectVec(vec2(x, y), vec2(width, height)) end sub
' Draw a filled in square sub FillSquareVec(pos() as single, size as single) FillRectVec(pos, vec2(size, size)) end sub
sub FillSquare(x as single, y as single, size as single) FillSquareVec(vec2(x, y), size) end sub
' Draw a filled in oval sub FillOvalVec(center() as single, size() as single) NewSprite(circleTex) SprSetPersistent(false) SprSetColor(penColor) SprSetPos(center) SprSetSize(size) end sub
sub FillOval(x as single, y as single, width as single, height as single) FillOvalVec(vec2(x, y), vec2(width, height)) end sub
' Draw a filled in circle sub FillCircleVec(center() as single, radius as single) FillOvalVec(center, vec2(radius * 2, radius * 2)) end sub
sub FillCircle(x as single, y as single, radius as single) FillCircleVec(vec2(x, y), radius) end sub
' Test drawing routines
' Note: Because drawing routines just create sprites, drawing coordinates are in sprite coordinates. ' By default 0,0 is the top left, and 640,480 is the bottom right. ' You can change the sprite coordinate range using: ResizeSpriteArea(width, height) ' If you want to work in pixel coordinates, uncomment this line: 'ResizeSpriteArea(WindowWidth(), WindowHeight())
TextMode(TEXT_BUFFERED)
penWidth = 3 DrawSquare(320 - 50, 240 - 50, 100)
penWidth = 1 penColor = vec3(100, 0, 0) dim i for i = 0 to 200 step 20 DrawOval(150, 200, 200, i) next
penColor = vec3(0, 100, 100) for i = 0 to 500 step 100 FillSquare(i + 20, 20, 60) next
penColor = vec3(0, 100, 0) for i = 0 to 500 step 100 FillCircle(i + 50, 410, 40) next
DrawText()
This uses the square and circle images from the gfx folder and stretches them into lines and various shapes. (A larger circle .png would give better quality filled circles). Hope this helps.
|
|
|
Post by Ben on Feb 18, 2017 8:04:43 GMT
That's cool. Thanks.
|
|
|
Post by mclout99 on Mar 26, 2017 14:57:45 GMT
Please do ADD graphic primitives. Circle, with x,y diamitor, start digree and stop degree, fill color RGB, fill patern. Simualy with Rect xy xy ect.. Line as well. Draw commnand with string instructions. All the classic Basic primitives.
|
|
|
Post by Tom on Mar 31, 2017 10:04:01 GMT
Please do ADD graphic primitives. Circle, with x,y diamitor, start digree and stop degree, fill color RGB, fill patern. Simualy with Rect xy xy ect.. Line as well. Draw commnand with string instructions. All the classic Basic primitives. That's a good idea. Would be useful to have. I'll add it to the to do list. Cheers, -Tom
|
|