From 967c5523a17f8d465354db4f402f553e5939b236 Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Tue, 22 Nov 2016 11:55:13 +0100 Subject: [PATCH] Added simple modelviewer --- modelviewer.py | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 modelviewer.py diff --git a/modelviewer.py b/modelviewer.py new file mode 100755 index 0000000..5f0440c --- /dev/null +++ b/modelviewer.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python3 + +import sys +import ctypes +import pygame + +from pygame.locals import * +from OpenGL.GL import * +from OpenGL.GLU import * +from OpenGL.GLUT import * + +from conv3d.loadmodel import load_model + +WINDOW_WIDTH = 1024 +WINDOW_HEIGHT = 768 + +x = -0.5 +y = 0.5 +width = 1 +height = 1 + +def init_frame(): + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) + glMatrixMode(GL_MODELVIEW) + glLoadIdentity() + gluLookAt(5,5,5,0,0,0,0,1,0) + +def main(args = {}): + + pygame.init() + display = (WINDOW_WIDTH, WINDOW_HEIGHT) + pygame.display.set_mode(display, DOUBLEBUF|OPENGL) + + # OpenGL init + glMatrixMode(GL_PROJECTION) + glLoadIdentity() + gluPerspective(45, (WINDOW_WIDTH / WINDOW_HEIGHT), 0.1, 50.0) + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) + glEnable(GL_DEPTH_TEST) + glEnable(GL_CULL_FACE) + glEnable(GL_BLEND) + glClearColor(0, 0, 0, 0) + + running = True + + model = load_model('./examples/cube.obj') + + while running: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + pygame.quit() + quit() + elif event.type == pygame.KEYUP: + if event.key == pygame.K_ESCAPE: + pygame.quit() + quit() + + init_frame() + model.gl_draw() + glFlush() + pygame.display.flip() + pygame.time.wait(10) + + +if __name__ == '__main__': + main()