Post by stu on Apr 30, 2006 18:14:46 GMT -5
This is my first contributed code. It's very basic (just whipped it up this afternoon), and the program is lacking many features, but it's a work in progress and the groundwork is there to add more colors and brush sizes. I might get around to adding them in one day, but for now, here it is.
'Basic4GL paint application'
'By Stu '
''''''''''''''''''''''''''''
'Controls: Left Mouse Button: paint
' Right Mouse Button: eraser
' Ctrl+D clears screen
' Ctrl+F fills screen with selected color
''''''''''''''''''''''''''''
const XSize = 640, YSize = 480
glMatrixMode (GL_PROJECTION)
glLoadIdentity ()
glOrtho (0, XSize, YSize, 0, 0, 1)
glMatrixMode (GL_MODELVIEW)
GlDisable(GL_DEPTH_TEST)
glClearColor(1.0,1.0,1.0,1.0)
dim ptcR, ptcB, ptcG
dim x1,x2,y1,y2
dim ptsize, eraserSize
ptsize = 2
eraserSize = 10
glClear(GL_COLOR_BUFFER_BIT)
glColor3f(0.0,0.0,0.0)
while true
glLoadIdentity()
'Formatting palette'''''
glColor3f(0.5,0.5,0.5)
glBegin(GL_QUADS)
glVertex2f(0.0,420.0)
glVertex2f(640.0,420.0)
glVertex2f(640.0,480.0)
glVertex2f(0.0,480.0)
glEnd()
if mouse_button(MOUSE_LBUTTON) then
gosub MakeBlocks:
end if
if mouse_button(MOUSE_RBUTTON) then
gosub Eraser:
end if
if ScanKeyDown(VK_CONTROL) and KeyDown("D") then
glClearColor(1.0,1.0,1.0,1.0)
gosub ClearScreen:
end if
if ScanKeyDown(VK_CONTROL) and keyDown("F") then
glClearColor(ptcR, ptcG, ptcB, 1.0)
gosub ClearScreen:
end if
SwapBuffers()
wend
MakeBlocks:
x1 = (640*mouse_X())
y1 = (480*mouse_y())
if y1 > (420-ptsize) then y1 = (420-ptsize) endif
glTranslatef(X1, y1, 0)
glColor3f (ptcR, ptcG, ptcB)
glBegin(GL_QUADS)
glVertex2f(-ptSize, ptSize): glVertex2f(ptSize, ptSize): glVertex2f(ptSize, -ptSize): glVertex2f(-ptSize, -ptSize)
glEnd()
return
Eraser:
x1 = (640*mouse_X())
y1 = (480*mouse_y())
if y1 > 410 then y1 = 410 endif
glTranslatef(X1, y1, 0)
glColor3f(1.0,1.0,1.0)
glBegin(GL_QUADS)
glVertex2f(-eraserSize, eraserSize): glVertex2f(eraserSize, eraserSize): glVertex2f(eraserSize, -eraserSize): glVertex2f(-eraserSize, -eraserSize)
glEnd()
return
ClearScreen:
glClear(GL_COLOR_BUFFER_BIT)
return