Skip to content

Instantly share code, notes, and snippets.

@akyoto
Created June 29, 2012 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akyoto/3017121 to your computer and use it in GitHub Desktop.
Save akyoto/3017121 to your computer and use it in GitHub Desktop.
import playground.Everything
# Check bp.Documentation in the module browser on the left for some beginner topics.
WIDTH : Int = 640
HEIGHT : Int = 480
win = GraphicsWindow("aaaa", WIDTH, HEIGHT)
setupGL()
for frame in win.frames
glColor3f 1.0, 1.0, 1.0
drawRect getMouseX() - 50, getMouseY() - 50, getMouseX() + 50, getMouseY() + 50, true
# -------------------------------------------------------------------------------------------------------------------
drawRect x1, y1, x2, y2, filled = true
glDisable GL_TEXTURE_2D
if filled
glBegin GL_QUADS
else
glBegin GL_LINE_STRIP
glVertex2i x1, y1
glVertex2i x1, y2
glVertex2i x2, y2
glVertex2i x2, y1
if not filled
glVertex2i x1, y1
glEnd()
glEnable GL_TEXTURE_2D
# -------------------------------------------------------------------------------------------------------------------
# -------------------------------------------------------------------------------------------------------------------
setupGL
# OpenGL params for gluerspective
# Field of view angle in Y
FOVy : Float64 = 0.0
# Aspect of screen
aspect : Float64 = 0.0
# z-near clip distance
znear : Float64 = 0.0
# z-far clip distance
zfar : Float64 = 0.0
# using screen info w and h as params
glViewport 0, 0, WIDTH, HEIGHT
# Set current Mode to projection(ie: 3d)
glMatrixMode GL_PROJECTION
# Load identity matrix to projection matrix
glLoadIdentity()
# Set gluPerspective params
# 45 deg fovy
FOVy = 90.0 / 2.0
Aspect = WIDTH / HEIGHT
# Near clip
znear = 1
# far clip
zfar = 500
# use glu Perspective to set our 3d frustum dimension up
gluPerspective FOVy, aspect, znear, zfar
# Modelview mode
# ie. Matrix that does things to anything we draw
# as in lines, points, tris, etc.
glMatrixMode GL_MODELVIEW
# load identity(clean) matrix to modelview
glLoadIdentity()
# set shading to smooth(try GL_FLAT)
glShadeModel GL_SMOOTH
# set Clear color to BLACK
glClearColor 0.0, 0.0, 0.0, 1.0
# Set Depth buffer to 1(z-Buffer)
glClearDepth 1.0
# Disable Depth Testing so that our z-buffer works
glDisable GL_DEPTH_TEST
# compare each incoming pixel z value with the z value present in the depth buffer
# LEQUAL means than pixel is drawn if the incoming z value is less than
# or equal to the stored z value
glDepthFunc GL_LEQUAL
# have one or more material parameters track the current color
# Material is your 3d model
glEnable GL_COLOR_MATERIAL
# Enable Texturing
glEnable GL_TEXTURE_2D
# Tell openGL that we want the best possible perspective transform
glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST
# Disable Backface culling
glDisable GL_CULL_FACE
glPolygonMode GL_FRONT, GL_FILL
# # enable blending for transparency
glEnable GL_BLEND
glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
glDisable GL_DEPTH_TEST
glEnable GL_ALPHA_TEST
glAlphaFunc GL_GREATER, 0
glDisable GL_STENCIL_TEST
glDisable GL_TEXTURE_1D
glDisable GL_LIGHTING
# glDisable(GL_LOGIC_OP) # ?
glDisable GL_DITHER
glDisable GL_FOG
glHint GL_POINT_SMOOTH_HINT, GL_FASTEST
glHint GL_LINE_SMOOTH_HINT, GL_FASTEST
glPointSize 1
glLineWidth 1
# # set up the font system
# font_init()
#start_2d(screen_wid, screen_hei)
glMatrixMode GL_PROJECTION
glPushMatrix()
glLoadIdentity()
glOrtho 0, WIDTH, HEIGHT, 0, -1, 1
glMatrixMode GL_MODELVIEW
glPushMatrix()
glLoadIdentity()
## magic trick
glTranslatef 0.375, 0.375, 0
# -------------------------------------------------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment