Skip to content

Instantly share code, notes, and snippets.

@mkassner
Created June 7, 2018 15:33
Show Gist options
  • Save mkassner/efb8638a98f2b23309ab6027b8c42683 to your computer and use it in GitHub Desktop.
Save mkassner/efb8638a98f2b23309ab6027b8c42683 to your computer and use it in GitHub Desktop.
for prp
# -*- coding: utf-8 -*-
import logging
from glfw import *
from OpenGL.GL import *
import numpy as np
# create logger for the context of this function
import time
from pyglui import ui
from pyglui.cygl.utils import init
from pyglui.cygl.utils import RGBA
from pyglui.pyfontstash import fontstash as fs
from pyglui.cygl.shader import Shader
width, height = (1280,300)
def basic_gl_setup():
glEnable(GL_POINT_SPRITE )
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE) # overwrite pointsize
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glEnable(GL_BLEND)
glClearColor(.8,.8,.8,1.)
glEnable(GL_LINE_SMOOTH)
# glEnable(GL_POINT_SMOOTH)
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)
glEnable(GL_LINE_SMOOTH)
glEnable(GL_POLYGON_SMOOTH)
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST)
def adjust_gl_view(w,h,window):
"""
adjust view onto our scene.
"""
print(w,h)
glViewport(0, 0, int(w), int(h))
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(0, w, h, 0, -1, 1)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
global quit
quit = False
# Callback functions
def on_resize(window,w, h):
h = max(h,1)
w = max(w,1)
hdpi_factor = glfwGetFramebufferSize(window)[0]/glfwGetWindowSize(window)[0]
w,h = w*hdpi_factor,h*hdpi_factor
active_window = glfwGetCurrentContext()
glfwMakeContextCurrent(active_window)
adjust_gl_view(w,h,window)
glfwMakeContextCurrent(active_window)
def on_close(window):
global quit
quit = True
logger.info('Process closing from window')
# get glfw started
glfwInit()
window = glfwCreateWindow(width, height, "pyglui demo", None, None)
if not window:
exit()
glfwSetWindowPos(window,0,0)
# Register callbacks for the window
glfwSetWindowSizeCallback(window,on_resize)
glfwSetWindowCloseCallback(window,on_close)
# test out new paste function
glfwMakeContextCurrent(window)
init()
basic_gl_setup()
import os
import psutil
pid = os.getpid()
ps = psutil.Process(pid)
ts = time.time()
from pyglui import graph
cpu_g = graph.Line_Graph(data_points=1100/2)
cpu_g.pos = (0,270)
cpu_g.update_fn = ps.cpu_percent
cpu_g.update_rate = 1
cpu_g.label = 'CPU %0.1f'
cpu_g2 = graph.Line_Graph(data_points=1110/2.)
cpu_g2.pos = (0,270)
cpu_g2.update_fn = lambda : ps.cpu_percent()
cpu_g2.update_rate = 1
cpu_g2.label = 'CPU %0.1f'
cpu_g2.scale =1
cpu_g.scale =1
on_resize(window,*glfwGetWindowSize(window))
fb_size = glfwGetFramebufferSize(window)
hdpi_factor = getHDPIFactor(window)
cpu_g.adjust_window_size(*fb_size)
cpu_g2.adjust_window_size(*fb_size)
while not quit:
cpu_g.update()
cpu_g.draw()
cpu_g2.update()
cpu_g2.draw()
glfwSwapBuffers(window)
glfwPollEvents()
glClearColor(.0,.0,.0,1)
glClear(GL_COLOR_BUFFER_BIT)
glfwTerminate()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment