Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import x
- import xlib
- import glx
- import opengl
- import glu
- var attr: array[0..4, int32] = [ GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None ]
- var swa: TXSetWindowAttributes
- var xev: TXEvent
- var gwa: TXWindowAttributes
- proc drawQuad() =
- glClearColor(1.0, 1.0, 1.0, 1.0)
- glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)
- glMatrixMode(GL_PROJECTION)
- glLoadIdentity()
- glOrtho(-1.0, 1.0, -1.0, 1.0, 1.0, 20.0)
- glMatrixMode(GL_MODELVIEW)
- glLoadIdentity()
- gluLookAt(0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
- glBegin(GL_QUADS)
- block draw:
- glColor3f(1.0, 0.0, 0.0)
- glVertex3f(-0.75, -0.75, 0.0)
- glColor3f(0.0, 1.0, 0.0)
- glVertex3f(0.75, -0.75, 0.0)
- glColor3f(0.0, 0.0, 1.0)
- glVertex3f(0.75, 0.75, 0.0)
- glColor3f(1.0, 1.0, 0.0)
- glVertex3f(-0.75, 0.75, 0.0)
- glEnd()
- let dpy = XOpenDisplay(nil)
- if dpy == nil:
- quit(1)
- let root = DefaultRootWindow(dpy)
- let vi = glXChooseVisual(dpy, 0, addr attr[0])
- if vi == nil:
- quit(2)
- let cmap = XCreateColormap(dpy, root, vi.visual, AllocNone)
- swa.colormap = cmap
- swa.event_mask = ExposureMask or KeyPressMask
- let win = XCreateWindow(dpy, root, 0, 0, 800, 600, 0, vi.depth, InputOutput, vi.visual, CWColorMap or CWEventMask, addr swa)
- discard XMapWindow(dpy, win)
- discard XStoreName(dpy, win, "Test 1")
- let glc = glXCreateContext(dpy, vi, nil, true)
- discard glXMakeCurrent(dpy, win, glc)
- glEnable(GL_DEPTH_TEST)
- while true:
- discard XNextEvent(dpy, addr xev)
- if xev.theType == Expose:
- discard XGetWindowAttributes(dpy, win, addr gwa)
- glViewport(0, 0, gwa.width, gwa.height)
- drawQuad()
- glXSwapBuffers(dpy, win)
- elif xev.theType == KeyPress:
- discard glXMakeCurrent(dpy, None, nil)
- glXDestroyContext(dpy, glc)
- discard XDestroyWindow(dpy, win)
- discard XCloseDisplay(dpy)
- quit(0)
Advertisement
Add Comment
Please, Sign In to add comment