Esempio n. 1
0
def main():
    '''
        Sample program to test GLWindow.
    '''

    print('GLWindow:', GLWindow.__version__)
    print('Python:', sys.version)
    print('Platform:', sys.platform)

    wnd = GLWindow.create_window((480, 480), title='GLWindow Sample')
    wnd.vsync = False

    ctx = ModernGL.create_context()

    prog = ctx.program([
        ctx.vertex_shader('''
            #version 330
            in vec2 vert;
            in vec4 vert_color;
            out vec4 frag_color;
            uniform vec2 scale;
            uniform float rotation;
            void main() {
                frag_color = vert_color;
                float r = rotation * (0.5 + gl_InstanceID * 0.05);
                mat2 rot = mat2(cos(r), sin(r), -sin(r), cos(r));
                gl_Position = vec4((rot * vert) * scale, 0.0, 1.0);
            }
        '''),
        ctx.fragment_shader('''
            #version 330
            in vec4 frag_color;
            out vec4 color;
            void main() {
                color = vec4(frag_color);
            }
        '''),
    ])

    scale = prog.uniforms['scale']
    rotation = prog.uniforms['rotation']

    vbo = ctx.buffer(struct.pack(
        '18f',
        1.0, 0.0, 1.0, 0.0, 0.0, 0.5,
        -0.5, 0.86, 0.0, 1.0, 0.0, 0.5,
        -0.5, -0.86, 0.0, 0.0, 1.0, 0.5,
    ))

    vao = ctx.simple_vertex_array(prog, vbo, ['vert', 'vert_color'])

    while wnd.update():
        wnd.clear(0.95, 0.95, 0.95)

        width, height = wnd.size
        scale.value = (height / width * 0.75, 0.75)
        ctx.viewport = wnd.viewport
        ctx.enable(ModernGL.BLEND)
        rotation.value = wnd.time
        vao.render(instances=10)
import struct

import GLWindow
import ModernGL
from pyrr import Matrix44

wnd = GLWindow.create_window()
ctx = ModernGL.create_context()

prog = ctx.program(
    ctx.vertex_shader('''
        #version 330

        uniform mat4 Mvp;

        in vec3 in_vert;
        in vec3 in_color;

        out vec3 v_color;

        void main() {
            v_color = in_color;
            gl_Position = Mvp * vec4(in_vert, 1.0);
        }
    '''),
    ctx.fragment_shader('''
        #version 330

        in vec3 v_color;
        out vec4 f_color;
import struct
import numpy

import GLWindow
import ModernGL

# This example is not working with NPOT Textures

pixels = numpy.round(numpy.random.rand(512, 512)).astype('float32')
grid = numpy.dstack(numpy.mgrid[0:512, 0:512][::-1] / 512).astype('float32')

wnd = GLWindow.create_window(512, 512)
ctx = ModernGL.create_context()

prog = ctx.program(
    ctx.vertex_shader('''
        #version 330

        in vec2 vert;
        out vec2 text;

        void main() {
            text = vert;
            gl_Position = vec4((vert * 2.0 - 1.0) * 1, 0.0, 1.0);
        }
    '''),
    ctx.fragment_shader('''
        #version 330

        uniform sampler2D Texture;
import struct
import numpy

import GLWindow
import ModernGL

# This example is not working with NPOT Textures

width, height = 640, 460

pixels = numpy.round(numpy.random.rand(width, height)).astype('float32')
grid = numpy.dstack(numpy.mgrid[0:height, 0:width][::-1]).astype('int32')

wnd = GLWindow.create_window(width, height)
ctx = ModernGL.create_context()

prog = ctx.program(
    ctx.vertex_shader('''
        #version 330

        in vec2 vert;
        out vec2 text;

        void main() {
            text = vert;
            gl_Position = vec4((vert * 2.0 - 1.0) * 1, 0.0, 1.0);
        }
    '''),
    ctx.fragment_shader('''
        #version 330
Esempio n. 5
0
import struct
import numpy

import GLWindow
import ModernGL

# This example is not working with NPOT Textures

width, height = 640, 460

pixels = numpy.round(numpy.random.rand(width, height)).astype('float32')
grid = numpy.dstack(numpy.mgrid[0:height, 0:width][::-1]).astype('int32')

wnd = GLWindow.create_window(width, height)
ctx = ModernGL.create_context()

prog = ctx.program([
    ctx.vertex_shader('''
        #version 330

        in vec2 vert;
        out vec2 text;

        void main() {
            text = vert;
            gl_Position = vec4((vert * 2.0 - 1.0) * 1, 0.0, 1.0);
        }
    '''),
    ctx.fragment_shader('''
        #version 330
Esempio n. 6
0
import GLWindow
import moderngl
from PIL import Image, ImageDraw, ImageFont
import numpy as np

wnd = GLWindow.create_window()
ctx = moderngl.create_context()

prog = ctx.program(
    vertex_shader='''
        #version 330

        in vec2 in_vert;
        in vec3 in_text;

        out vec3 v_text;

        void main() {
            v_text = in_text;
            gl_Position = vec4(in_vert, 0.0, 1.0);
        }
    ''',
    fragment_shader='''
        #version 330

        uniform sampler2DArray Texture;

        in vec3 v_text;

        out vec4 f_color;
Esempio n. 7
0
# import neccessary modules

# ModernGL will do the rendering
import ModernGL as GL

# GLWindow will create a window with a valid OpenGL context
import GLWindow as WND

# We will need the struct module to create data for buffers
import struct

# GLWindow.Init() will initialize the GLWindow module and create
# a hidden window with a valid OpenGL context

WND.Init()
Esempio n. 8
0
import GLWindow as WND
import ModernGL as GL
import numpy, random
import math

WND.Init()
GL.Init()

points = GL.NewProgram([
    GL.NewVertexShader('''
		#version 330 core

		in vec2 vert;
		uniform vec2 scale;

		void main() {
			gl_Position = vec4(vert / scale, 0.0, 1.0);
		}
	'''),
    GL.NewGeometryShader('''
		#version 330 core

		layout(points) in;
		layout(line_strip, max_vertices = 17) out;

		uniform vec2 scale;

		void main() {
			for (int i = 0; i <= 16; ++i) {
				float a = 3.14159265 * 2.0 * ((i * 6) / 16.0);
				vec2 move = vec2(cos(a) * 0.1, sin(a) * 0.1) / scale;
Esempio n. 9
0
import ModernGL as GL
import GLWindow as WND
import struct, time

WND.Init()
GL.Init()

vert = GL.NewVertexShader('''
	#version 330

	uniform vec2 pos;
	uniform float zoom;

	in vec2 vert;
	out vec2 textcoord;

	void main() {
		gl_Position = vec4(vert, 0.0, 1.0);
		textcoord = ((vert + pos) * zoom) / 2.0 + vec2(0.5, 0.5);
	}
''')

frag = GL.NewFragmentShader('''
	#version 330
	
	in vec2 textcoord;
	out vec4 color;

	uniform int iter;

	void main() {
Esempio n. 10
0
import ModernGL as GL
import GLWindow as WND
import struct

WND.Init()
GL.Init()

vert = GL.NewVertexShader('''
	#version 330

	in vec3 vert;

	uniform float znear;
	uniform float zfar;
	uniform float fovy;
	uniform float ratio;

	uniform vec3 center;
	uniform vec3 eye;
	uniform vec3 up;

	mat4 perspective() {
		float zmul = (-2.0 * znear * zfar) / (zfar - znear);
		float ymul = 1.0 / tan(fovy * 3.14159265 / 360);
		float xmul = ymul / ratio;

		return mat4(
			xmul, 0.0, 0.0, 0.0,
			0.0, ymul, 0.0, 0.0,
			0.0, 0.0, -1.0, -1.0,
			0.0, 0.0, zmul, 0.0
Esempio n. 11
0
	math.cos(2 * math.pi * 3 / 3 + 2 * math.pi / 3 * 3 / 6), math.sin(2 * math.pi * 3 / 3 + 2 * math.pi / 3 * 3 / 6), -0.3, 0.6,
	math.cos(2 * math.pi * 2 / 3 + 2 * math.pi / 3 * 3 / 6), math.sin(2 * math.pi * 2 / 3 + 2 * math.pi / 3 * 3 / 6), -0.3, 0.6,
	math.cos(2 * math.pi * 1 / 3 + 2 * math.pi / 3 * 3 / 6), math.sin(2 * math.pi * 1 / 3 + 2 * math.pi / 3 * 3 / 6), -0.3, 0.6,

	math.cos(2 * math.pi * 1 / 3 + 2 * math.pi / 3 * 2 / 6), math.sin(2 * math.pi * 1 / 3 + 2 * math.pi / 3 * 2 / 6), -0.2, 0.5,
	math.cos(2 * math.pi * 2 / 3 + 2 * math.pi / 3 * 2 / 6), math.sin(2 * math.pi * 2 / 3 + 2 * math.pi / 3 * 2 / 6), -0.2, 0.5,
	math.cos(2 * math.pi * 3 / 3 + 2 * math.pi / 3 * 2 / 6), math.sin(2 * math.pi * 3 / 3 + 2 * math.pi / 3 * 2 / 6), -0.2, 0.5,

	math.cos(2 * math.pi * 3 / 3 + 2 * math.pi / 3 * 1 / 6), math.sin(2 * math.pi * 3 / 3 + 2 * math.pi / 3 * 1 / 6), -0.1, 0.4,
	math.cos(2 * math.pi * 2 / 3 + 2 * math.pi / 3 * 1 / 6), math.sin(2 * math.pi * 2 / 3 + 2 * math.pi / 3 * 1 / 6), -0.1, 0.4,
	math.cos(2 * math.pi * 1 / 3 + 2 * math.pi / 3 * 1 / 6), math.sin(2 * math.pi * 1 / 3 + 2 * math.pi / 3 * 1 / 6), -0.1, 0.4,
]

# CTX.Context(True)
GLWindow.InitializeWindow()
GLWindow.BuildFullscreen()

GL.InitializeModernGL()

print(GL.GetInfo())

if not os.path.isdir('TestResults'):
	os.mkdir('TestResults')

# GL.BuildMipmap()

# GL.DeleteComputeShader()
# GL.DeleteFramebuffer()
# GL.DeleteIndexBuffer()
# GL.DeleteProgram()
Esempio n. 12
0
import struct
import numpy

import GLWindow
import ModernGL

# This example is not working with NPOT Textures

pixels = numpy.round(numpy.random.rand(512, 512)).astype('float32')
grid = numpy.dstack(numpy.mgrid[0:512, 0:512][::-1] / 512).astype('float32')

wnd = GLWindow.create_window(512, 512)
ctx = ModernGL.create_context()

prog = ctx.program([
    ctx.vertex_shader('''
        #version 330

        in vec2 vert;
        out vec2 text;

        void main() {
            text = vert;
            gl_Position = vec4((vert * 2.0 - 1.0) * 1, 0.0, 1.0);
        }
    '''),
    ctx.fragment_shader('''
        #version 330

        uniform sampler2D Texture;
Esempio n. 13
0
import ModernGL as GL
import GLWindow as WND
import struct

WND.Init()
GL.Init()

vert = GL.NewVertexShader('''
	#version 330

	in vec2 vert;

	in vec4 vert_color;
	out vec4 frag_color;

	uniform vec2 scale;
	uniform float rotation;

	void main() {
		frag_color = vert_color;
		float r = rotation * (0.5 + gl_InstanceID * 0.05);
		mat2 rot = mat2(cos(r), sin(r), -sin(r), cos(r));
		gl_Position = vec4((rot * vert) * scale, 0.0, 1.0);
	}
''')

frag = GL.NewFragmentShader('''
	#version 330
	
	in vec4 frag_color;
	out vec4 color;