specific hacks in video.py Added a config file (settings.cfg) Added functionality for saving last used window position! Added displaylists to models.py Broke fonts (temporarily)
142 lines
3.1 KiB
Python
Executable file
142 lines
3.1 KiB
Python
Executable file
import os
|
|
from OpenGL.GL import *
|
|
from OpenGL.GLU import *
|
|
from OpenGL.arrays import GLcharArray
|
|
import pygame
|
|
from pygame.locals import *
|
|
import sys
|
|
import shader
|
|
import config
|
|
import platform
|
|
|
|
height=None
|
|
width=None
|
|
hwnd=None
|
|
|
|
def enable_vsync():
|
|
platform.enable_vsync()
|
|
|
|
def skipping_next_frame():
|
|
return False
|
|
def set_res((width_in, height_in)):
|
|
global height, width, hwnd
|
|
|
|
load_window_pos()
|
|
|
|
height = height_in
|
|
width = width_in
|
|
|
|
if height==0:
|
|
height=1
|
|
if width==0:
|
|
width=1
|
|
#pygame.display.gl_set_attribute(GL_DEPTH_SIZE, 24)
|
|
video_flags = OPENGL|DOUBLEBUF
|
|
#video_flags = OPENGL|DOUBLEBUF|FULLSCREEN
|
|
pygame.display.set_mode((width, height), video_flags)
|
|
hwnd = platform.get_window_handle()
|
|
|
|
def get_res():
|
|
return (width, height)
|
|
|
|
def get_height():
|
|
return height
|
|
|
|
def get_width():
|
|
return width
|
|
|
|
def save_window_pos():
|
|
global hwnd
|
|
wpos = platform.get_window_rect(hwnd)
|
|
|
|
if not wpos is None:
|
|
config.mgr.write_key('windowpos', '%s,%s' % wpos[0:2])
|
|
|
|
def load_window_pos():
|
|
windowpos = config.mgr.read_key('windowpos')
|
|
|
|
if windowpos is None:
|
|
return
|
|
|
|
os.environ['SDL_VIDEO_WINDOW_POS'] = windowpos
|
|
|
|
|
|
def init2d():
|
|
#print pygame.display.gl_get_attribute(GL_DEPTH_SIZE)
|
|
glViewport(0, 0, width, height)
|
|
glMatrixMode(GL_PROJECTION)
|
|
glLoadIdentity()
|
|
glOrtho(0.0, float(width), float(height), 0.0, 256.0, -256.0)
|
|
glMatrixMode(GL_MODELVIEW)
|
|
glLoadIdentity()
|
|
#glRotatef(120.0, 1.0, 0.0, 0.0)
|
|
|
|
|
|
glClearColor(0.0, 0.0, 0.0, 0.0)
|
|
glClearDepth(-256.0)
|
|
|
|
glShadeModel(GL_SMOOTH)
|
|
glEnable(GL_DEPTH_TEST)
|
|
glEnable(GL_CULL_FACE)
|
|
glEnable(GL_TEXTURE_2D)
|
|
glDepthFunc(GL_GEQUAL)
|
|
glEnable(GL_BLEND)
|
|
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
|
|
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, (0.3, 0.3, 0.3, 1.0))
|
|
|
|
shader.mgr.load()
|
|
shader.mgr.init_gl()
|
|
shader.mgr.select("ffp")
|
|
glDisable(GL_LIGHTING)
|
|
|
|
|
|
def init3d():
|
|
#print pygame.display.gl_get_attribute(GL_DEPTH_SIZE)
|
|
glViewport(0, 0, width, height)
|
|
glMatrixMode(GL_PROJECTION)
|
|
glLoadIdentity()
|
|
gluPerspective(45, 1.0*width/height, 1.0, 10e6)
|
|
glMatrixMode(GL_MODELVIEW)
|
|
glLoadIdentity()
|
|
|
|
glShadeModel(GL_SMOOTH)
|
|
glClearColor(0.0, 0.0, 0.0, 0.0)
|
|
glClearDepth(1.0)
|
|
glEnable(GL_DEPTH_TEST)
|
|
glEnable(GL_CULL_FACE)
|
|
glEnable(GL_TEXTURE_2D)
|
|
glDepthFunc(GL_LEQUAL)
|
|
#glEnable(GL_BLEND)
|
|
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
|
|
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0)
|
|
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1)
|
|
"""
|
|
"""
|
|
LightAmbient = ( (0.2, 0.2, 0.2, 1.0) )
|
|
LightDiffuse = ( (0.5, 0.5, 0.5, 1.0) )
|
|
LightPosition = ( (0.0, 0.2, 2.0, 1.0) )
|
|
glEnable(GL_LIGHTING)
|
|
glLightfv( GL_LIGHT1, GL_AMBIENT, LightAmbient )
|
|
glLightfv( GL_LIGHT1, GL_DIFFUSE, LightDiffuse )
|
|
glLightfv( GL_LIGHT1, GL_POSITION, LightPosition )
|
|
glEnable( GL_LIGHT1 )
|
|
"""
|
|
"""
|
|
|
|
shader.mgr.load()
|
|
shader.mgr.init_gl()
|
|
shader.mgr.select("standard")
|
|
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, (0.3, 0.3, 0.3, 1.0))
|
|
#glEnable(GL_AUTO_NORMAL)
|
|
|
|
|
|
def predraw():
|
|
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
|
|
glLoadIdentity()
|
|
|
|
#glTranslatef(-1.0, 0.0, -9.0)
|
|
#glRotatef(270.0, 1.0, 0.0, 0.0)
|
|
|
|
def next_frame():
|
|
pygame.display.flip()
|
|
|