0% found this document useful (0 votes)
38 views3 pages

Setup A 2D Projection

The document sets up a 2D projection in OpenGL and defines variables and functions to draw different shapes like points, lines, rectangles, circles. It then calls these functions to draw a scene with various shapes like a hollow rectangle, line, solid rectangle, another line, many random points, a solid circle, and several hollow circles with different radii. The program clears the color buffer and swaps the buffers after drawing.

Uploaded by

ayu5787
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views3 pages

Setup A 2D Projection

The document sets up a 2D projection in OpenGL and defines variables and functions to draw different shapes like points, lines, rectangles, circles. It then calls these functions to draw a scene with various shapes like a hollow rectangle, line, solid rectangle, another line, many random points, a solid circle, and several hollow circles with different radii. The program clears the color buffer and swaps the buffers after drawing.

Uploaded by

ayu5787
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

// Setup a 2D projection

const XSize = 640, YSize = 480


glMatrixMode (GL_PROJECTION)
glLoadIdentity ()
glOrtho (0, XSize, YSize, 0, 0, 1)
glDisable(GL_DEPTH_TEST)
glMatrixMode (GL_MODELVIEW)
glLoadIdentity()
//Displacement trick for exact pixelization
glTranslatef(0.375, 0.375, 0)

//Variables
dim angle#, x1, y1, x2, y2, radius#
dim i

//Draw a scene
glClearColor(.3, .3, .3, 0)
glClear(GL_COLOR_BUFFER_BIT)

x1 = 20: y1 = 20: x2 = 620: y2 = 460: gosub HollowRectangle


x1 = 20: y1 = 40: x2 = 620: y2 = 40: gosub Line
x1 = 602: y1 = 22: x2 = 618: y2 = 37: gosub Rectangle
x1 = 580: y1 = 460: x2 = 620: y2 = 420: gosub Line

for i = 1 to 5000
x1 = rnd() % 600 + 20
y1 = rnd() % 420 + 40
gosub Point
next

x1 = 320: y1 = 240: radius# = 20: gosub Circle


x1 = 320: y1 = 240: radius# = 40: gosub HollowCircle
x1 = 320: y1 = 240: radius# = 60: gosub HollowCircle
x1 = 320: y1 = 240: radius# = 80: gosub HollowCircle

SwapBuffers()
End

Point:
glBegin(GL_POINTS)
glVertex2f(x1 + 0.5, y1 + 0.5)
glEnd()
return

Line:
glBegin(GL_LINES)
glVertex2f(x1, y1): glVertex2f(x2, y2)
glEnd()
return

Rectangle:
glBegin(GL_QUADS)
glVertex2f(x1, y1): glVertex2f(x2, y1): glVertex2f(x2, y2): glVertex2f(x1,
y2)
glEnd()
return

HollowRectangle:

glBegin(GL_LINE_LOOP)
glVertex2f(x1, y1): glVertex2f(x2, y1): glVertex2f(x2, y2): glVertex2f(x1,
y2)
glEnd()
return

Circle:
glBegin(GL_TRIANGLE_FAN)
glVertex2f(x1, y1)
for angle# = 0 to 360 step 5
glVertex2f(x1 + sind(angle#) * radius#, y1 + cosd(angle#) * radius#)
next
glEnd()
return

HollowCircle:
glBegin(GL_LINE_LOOP)
for angle# = 0 to 360 step 5
glVertex2f(x1 + sind(angle#) * radius#, y1 + cosd(angle#) * radius#)
next
glEnd()
return
{

You might also like