Esempio n. 1
0
	def draw(self):
		"Draw the interface."
		
		# Refit
		
		if self.mess:
			self._refitting_state = True
			for e in self.mess:
				e._refit()
			self._refitting_state = False
			self.mess = set()
			self.mousemove()
		
		# Draw no matter what if the interface is seethrough
		if not self.body.soliddraw:
			self.body.dirty = True
		
		if self.body.dirty:
			self.window.enable('scissor')
			self.body._draw(Bounds(self.body.style.offset, self.body.style.size), Offset(self.body.style.offset))
			self.body.dirty = False
			self.window.enable('scissor', False)
		
			self.window.viewport(glm.ivec4(Bounds(self.body.style.offset, self.body.style.size)))
			
			if self.dragging:
				self.dragging.drag.draw()
		
			return True
		return False
Esempio n. 2
0
	def _draw(self, _clip, _offset = Offset(), parent_draw = False):
		if parent_draw:
			self.dirty = True
		
		parent_draw = self.dirty == True
		
		if not self.imaginary or isinstance(self.dirty, tuple):
			b = Bounds(_offset, self.style.size)

			if not self.imaginary:
				_clip.overlap(b)
			
			if isinstance(self.dirty, tuple):
				_clip.overlap(self.dirty[1] + _offset)
			if not _clip.valid():
				self.dirty = False
				return
			
			self.interface._clip = glm.ivec4(_clip)
			self.interface._viewport = glm.ivec4(b)
			self.interface.window.viewport(self.interface._viewport)
			self.interface.window.scissor(self.interface._clip)
		
		if isinstance(self.dirty, tuple):
			drawc = True
			startfrom = self.children.index(self.dirty[0])
		else:
			drawc = self.draw() is not False
			startfrom = 0
		
		self.dirty = False
		
		if drawc:
			if startfrom:
				for e in self.children[startfrom:]:
					e._draw(Bounds(_clip), Offset(_offset + e.style.offset), parent_draw)
			else:
				for e in self.children:
					e._draw(Bounds(_clip), Offset(_offset + e.style.offset), parent_draw)
Esempio n. 3
0
    def __init__(self, app, scene, size=None):
        super().__init__(app, scene)

        self.app = app
        self.scene = scene

        self.font_size = ivec2(size or 24)
        self.spacing = ivec2(0)
        font_fn = path.join(FONTS_DIR, "PressStart2P-Regular.ttf")

        # load the font if its not already loaded (cacheble)
        # we're appending :16 to cache name since we may need to cache
        # different sizes in the future
        self.font = self.app.load(
            (font_fn, self.font_size.y),
            lambda: pygame.font.Font(font_fn, self.font_size.y, bold=True),
        )

        # terminal size in characters
        self.size = app.size / (self.font_size + self.spacing)

        # dirty flags for lazy redrawing
        self.dirty = True
        self.dirty_line = [True] * self.size.y  # dirty flags per line

        self._offset = ivec2(0, 0)

        # 2d array of pygame text objects
        self.chars = []
        for y in range(self.size.y):
            self.chars.append([None] * self.size.x)

        self.surface = pygame.Surface(self.app.size, pygame.SRCALPHA,
                                      32).convert_alpha()

        self.bg_color = ivec4(255, 255, 255, 0)  # transparent by default
        self.shadow_color = ivec4(120, 120, 120, 0)
        self.shadow2_color = ivec4(0, 0, 0, 0)
    def __init__(self, width, height):
        global m_vao
        global m_vbo

        i = 0
        j = 0

        load_shaders()

        initial_positions = [glm.vec4() for _ in range(POINTS_TOTAL)]
        initial_velocities = [glm.vec3() for _ in range(POINTS_TOTAL)]
        connection_vectors = [glm.ivec3() for _ in range(POINTS_TOTAL)]

        n = 0
        for j in range(0, POINTS_Y):
            fj = float(j) / float(POINTS_Y)

            for i in range(0, POINTS_X):

                fi = float(i) / float(POINTS_X)

                initial_positions[n] = glm.vec4((fi - 0.5) * float(POINTS_X),
                                                (fj - 0.5) * float(POINTS_Y),
                                                0.6 * sin(fi) * cos(fj), 1.0)
                initial_velocities[n] = glm.vec3(0.0)
                connection_vectors[n] = glm.ivec4(-1)

                if (j != (POINTS_Y - 1)):

                    if (i != 0):
                        connection_vectors[n][0] = n - 1

                    if (j != 0):
                        connection_vectors[n][1] = n - POINTS_X

                    if (i != (POINTS_X - 1)):
                        connection_vectors[n][2] = n + 1

                    if (j != (POINTS_Y - 1)):
                        connection_vectors[n][3] = n + POINTS_X
                n += 1

        for i in range(0, 2):
            glGenVertexArrays(1, m_vao[i])

        for i in range(0, 5):
            glGenBuffers(i + 1, m_vbo[i])

        for i in range(0, 2):

            glBindVertexArray(m_vao[i])

            glBindBuffer(GL_ARRAY_BUFFER, m_vbo[POSITION_A + i])

            # POSITION_A
            glBindBuffer(GL_ARRAY_BUFFER, m_vbo[POSITION_A + i])

            ar_position = np.empty([POINTS_TOTAL, 4], dtype='float32')
            for j, e in enumerate(initial_positions):
                ar_position[j] = e

            glBufferData(GL_ARRAY_BUFFER,
                         POINTS_TOTAL * glm.sizeof(glm.vec4()), ar_position,
                         GL_DYNAMIC_COPY)
            glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, None)
            glEnableVertexAttribArray(0)

            # VELOCITY_A
            glBindBuffer(GL_ARRAY_BUFFER, m_vbo[VELOCITY_A + i])

            ar_velocities = np.empty([POINTS_TOTAL, 3], dtype='float32')
            for j, e in enumerate(initial_velocities):
                ar_velocities[j] = e

            glBufferData(GL_ARRAY_BUFFER,
                         POINTS_TOTAL * glm.sizeof(glm.vec3()), ar_velocities,
                         GL_DYNAMIC_COPY)
            glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, None)
            glEnableVertexAttribArray(1)

            # CONNECTION
            glBindBuffer(GL_ARRAY_BUFFER, m_vbo[CONNECTION])

            ar_connection = np.empty([POINTS_TOTAL, 4], dtype='uint32')
            for j, e in enumerate(connection_vectors):
                ar_connection[j] = e

            glBufferData(GL_ARRAY_BUFFER,
                         POINTS_TOTAL * glm.sizeof(glm.ivec4()), ar_connection,
                         GL_STATIC_DRAW)
            glVertexAttribIPointer(2, 4, GL_INT, 0, None)
            glEnableVertexAttribArray(2)

        glGenTextures(2, m_pos_tbo)
        glBindTexture(GL_TEXTURE_BUFFER, m_pos_tbo[0])
        glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32F, m_vbo[POSITION_A])
        glBindTexture(GL_TEXTURE_BUFFER, m_pos_tbo[1])
        glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32F, m_vbo[POSITION_B])

        lines = (POINTS_X - 1) * POINTS_Y + (POINTS_Y - 1) * POINTS_X

        glGenBuffers(1, m_index_buffer)
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_index_buffer)
        glBufferData(GL_ELEMENT_ARRAY_BUFFER,
                     lines * 2 * ctypes.sizeof(ctypes.c_int), None,
                     GL_STATIC_DRAW)

        e = glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER, 0,
                             lines * 2 * ctypes.sizeof(ctypes.c_int),
                             GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT)

        int_array = (ctypes.c_int * (4 * lines * 2)).from_address(e)
        n = 0
        for j in range(0, POINTS_Y):
            for i in range(0, POINTS_X - 1):
                int_array[n] = i + j * POINTS_X
                n += 1

                int_array[n] = 1 + i + j * POINTS_X
                n += 1

        for i in range(0, POINTS_X):

            for j in range(0, POINTS_Y - 1):
                int_array[n] = i + j * POINTS_X
                n += 1

                int_array[n] = POINTS_X + i + j * POINTS_X
                n += 1

        glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER)
Esempio n. 5
0
fassert(glm.unpackUnorm1x5_1x6_1x5, (0,))
fassert(glm.packUnorm3x5_1x1, (glm.vec4(),))
fassert(glm.unpackUnorm3x5_1x1, (0,))
fassert(glm.packUnorm2x3_1x2, (glm.vec3(),))
fassert(glm.unpackUnorm2x3_1x2, (0,))
fassert(glm.packSnorm1x8, (0.,))
fassert(glm.unpackSnorm1x8, (0,))
fassert(glm.packSnorm2x8, (glm.vec2(),))
fassert(glm.unpackSnorm2x8, (0,))
fassert(glm.packSnorm1x16, (0.,))
fassert(glm.unpackSnorm1x16, (0,))
fassert(glm.packSnorm4x16, (glm.vec4(),))
fassert(glm.unpackSnorm4x16, (0,))
fassert(glm.packSnorm3x10_1x2, (glm.vec4(),))
fassert(glm.unpackSnorm3x10_1x2, (0,))
fassert(glm.packI3x10_1x2, (glm.ivec4(),))
fassert(glm.unpackI3x10_1x2, (0,))
fassert(glm.packU3x10_1x2, (glm.uvec4(),))
fassert(glm.unpackU3x10_1x2, (0,))
fassert(glm.packF2x11_1x10, (glm.vec3(),))
fassert(glm.unpackF2x11_1x10, (0,))
fassert(glm.packF3x9_E1x5, (glm.vec3(),))
fassert(glm.unpackF3x9_E1x5, (0,))

for args in gen_args("V3__fF"):
    fassert(glm.packRGBM, args)

for args in gen_args("V4__fF"):
    fassert(glm.unpackRGBM, args)

for args in gen_args("V__f"):
Esempio n. 6
0
 def value(self):
     v = b'\x00' * 16
     native.n_svivec4_value(self.m_cptr, ffi.from_buffer('int[]', v))
     return glm.ivec4(struct.unpack('4i', v))