Ejemplo n.º 1
0
    def display(self):

        currentTime = time.time()
        t = currentTime * 0.02

        r = 550.0

        black = [0.0, 0.0, 0.0, 1.0]
        one = 1.0
        glClearBufferfv(GL_COLOR, 0, black)
        glClearBufferfv(GL_DEPTH, 0, one)

        mv_matrix = (GLfloat * 16)(*identityMatrix)
        mv_matrix = m3dLookAt([sin(t) * r, 25.0, cos(t) * r],
                              [0.0, -50.0, 0.0], [0.0, 1.0, 0.0])

        prj_matrix = (GLfloat * 16)(*identityMatrix)
        prj_matrix = m3dPerspective(m3dDegToRad(45.0),
                                    float(self.width) / float(self.height),
                                    0.1, 1000.0)

        glUseProgram(grass_program)
        glUniformMatrix4fv(uniform.mvpMatrix, 1, GL_FALSE,
                           m3dMultiply(prj_matrix, mv_matrix))

        glEnable(GL_DEPTH_TEST)
        glDepthFunc(GL_LEQUAL)

        glViewport(0, 0, self.width, self.height)

        glBindVertexArray(grass_vao)
        glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 6, 1024 * 1024)

        glutSwapBuffers()
Ejemplo n.º 2
0
    def display(self):

        global myobject

        currentTime = time.time()

        j = 0
        one = 1.0
        black = [0.0, 0.0, 0.0, 0.0]

        last_time = 0.0
        total_time = 0.0

        if (paused == False):
            total_time += (currentTime - last_time)
        last_time = currentTime

        t = float(total_time)
        i = int(total_time * 3.0)

        glViewport(0, 0, self.width, self.height)
        glClearBufferfv(GL_COLOR, 0, black)
        glClearBufferfv(GL_DEPTH, 0, one)

        view_matrix = (GLfloat * 16)(*identityMatrix)
        view_matrix = m3dLookAt([
            100.0 * cos(t * 0.023), 100.0 * cos(t * 0.023),
            300.0 * sin(t * 0.037) - 600.0
        ], [0.0, 0.0, 260.0], normalize([0.1 - cos(t * 0.1) * 0.3, 1.0, 0.0]))

        proj_matrix = (GLfloat * 16)(*identityMatrix)
        proj_matrix = m3dPerspective(m3dDegToRad(50.0),
                                     float(self.width) / float(self.height),
                                     1.0, 2000.0)

        glUseProgram(render_program)

        glUniform1f(uniform.time, t)
        glUniformMatrix4fv(uniform.view_matrix, 1, GL_FALSE, view_matrix)
        glUniformMatrix4fv(uniform.proj_matrix, 1, GL_FALSE, proj_matrix)
        glUniformMatrix4fv(uniform.viewproj_matrix, 1, GL_FALSE,
                           m3dMultiply(proj_matrix, view_matrix))

        glBindVertexArray(myobject.get_vao())

        if (mode == MODE_MULTIDRAW):

            glMultiDrawArraysIndirect(GL_TRIANGLES, None, NUM_DRAWS, 0)

        elif (mode == MODE_SEPARATE_DRAWS):

            for j in range(0, NUM_DRAWS):

                first, count = myobject.get_sub_object_info(
                    j % myobject.get_sub_object_count())
                glDrawArraysInstancedBaseInstance(GL_TRIANGLES, first, count,
                                                  1, j)

        glutSwapBuffers()
    def display(self):

        currentTime = time.time()

        gray = [ 0.2, 0.2, 0.2, 1.0 ]
        ones = [ 1.0 ]
        t = currentTime * 0.1

        proj_matrix = (GLfloat * 16)(*identityMatrix)
        proj_matrix = m3dPerspective(m3dDegToRad(60.0), float(self.width) / float(self.height), 0.1, 1000.0);    

        view_matrix = (GLfloat * 16)(*identityMatrix)
        view_matrix = m3dLookAt([15.0 * sin(t), 0.0, 15.0 * cos(t)],
                                (0.0, 0.0, 0.0),
                                (0.0, 1.0, 0.0))
               
        RX = (GLfloat * 16)(*identityMatrix)
        m3dRotationMatrix44(RX, t * m3dDegToRad(0.0), 1.0, 0.0, 0.0)
                                                  
        RY = (GLfloat * 16)(*identityMatrix)
        m3dRotationMatrix44(RY, t * m3dDegToRad(130.1), 0.0, 1.0, 0.0)
                    
        T = (GLfloat * 16)(*identityMatrix)
        m3dTranslateMatrix44(T, 0.0, -4.0, 0.0)

        mv_matrix = (GLfloat * 16)(*identityMatrix)
        mv_matrix = m3dMultiply(RX, m3dMultiply(RY, T))
        
        mv_matrix = m3dMultiply(view_matrix , mv_matrix)

        glClearBufferfv(GL_COLOR, 0, gray)
        glClearBufferfv(GL_DEPTH, 0, ones)
        glBindTexture(GL_TEXTURE_CUBE_MAP, tex_envmap)

        glViewport(0, 0, self.width, self.height)

        glUseProgram(skybox_prog)
        glBindVertexArray(skybox_vao)

        glUniformMatrix4fv(uniforms.skybox.view_matrix, 1, GL_FALSE, view_matrix)

        glDisable(GL_DEPTH_TEST)

        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)

        glUseProgram(render_prog)

        glUniformMatrix4fv(uniforms.render.mv_matrix, 1, GL_FALSE, mv_matrix)
        glUniformMatrix4fv(uniforms.render.proj_matrix, 1, GL_FALSE, proj_matrix)

        glEnable(GL_DEPTH_TEST)

        myobject.render()

        glutSwapBuffers()
Ejemplo n.º 4
0
    def display(self):
        global last_time
        global total_time

        currentTime = time.time()

        uint_zeros = [0, 0, 0, 0]
        float_zeros = [0.0, 0.0, 0.0, 0.0]
        float_ones = [1.0, 1.0, 1.0, 1.0]
        draw_buffers = [GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1]

        if (not paused):

            total_time += (currentTime - last_time)

        last_time = currentTime

        t = total_time

        glBindFramebuffer(GL_FRAMEBUFFER, gbuffer)
        glViewport(0, 0, self.width, self.height)
        glDrawBuffers(2, draw_buffers)
        glClearBufferuiv(GL_COLOR, 0, uint_zeros)
        glClearBufferuiv(GL_COLOR, 1, uint_zeros)
        glClearBufferfv(GL_DEPTH, 0, float_ones)

        glBindBufferBase(GL_UNIFORM_BUFFER, 0, render_transform_ubo)

        matrices = glMapBufferRange(
            GL_UNIFORM_BUFFER, 0, (2 + NUM_INSTANCES) * glm.sizeof(glm.mat4),
            GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT)

        matricesp = (GLfloat * 16 * (2 + NUM_INSTANCES)).from_address(matrices)

        proj_matrix = (GLfloat * 16)(*identityMatrix)
        proj_matrix = m3dPerspective(m3dDegToRad(50.0),
                                     float(self.width) / float(self.height),
                                     0.1, 1000.0)

        matricesp[0] = proj_matrix

        d = (sin(t * 0.131) + 2.0) * 0.15
        eye_pos = (d * 120.0 * sin(t * 0.11), 5.5, d * 120.0 * cos(t * 0.01))

        view_matrix = (GLfloat * 16)(*identityMatrix)
        view_matrix = m3dLookAt(eye_pos, (0.0, -20.0, 0.0), (0.0, 1.0, 0.0))

        matricesp[1] = (GLfloat * 16)(*view_matrix)

        for j in range(0, 15):

            j_f = float(j)

            for i in range(0, 15):

                i_f = float(i)

                T = (GLfloat * 16)(*identityMatrix)
                m3dTranslateMatrix44(T, (i - 7.5) * 7.0, 0.0, (j - 7.5) * 11.0)

                matricesp[j * 15 + i + 2] = T

        glUnmapBuffer(GL_UNIFORM_BUFFER)

        glUseProgram(render_program_nm if use_nm else render_program)

        glActiveTexture(GL_TEXTURE0)
        glBindTexture(GL_TEXTURE_2D, tex_diffuse)
        glActiveTexture(GL_TEXTURE1)
        glBindTexture(GL_TEXTURE_2D, tex_nm)

        glEnable(GL_DEPTH_TEST)
        glDepthFunc(GL_LEQUAL)

        myobject.render(NUM_INSTANCES)

        glBindFramebuffer(GL_FRAMEBUFFER, 0)
        glViewport(0, 0, self.width, self.height)
        glDrawBuffer(GL_BACK)

        glActiveTexture(GL_TEXTURE0)
        glBindTexture(GL_TEXTURE_2D, gbuffer_tex[0])

        glActiveTexture(GL_TEXTURE1)
        glBindTexture(GL_TEXTURE_2D, gbuffer_tex[1])

        if (vis_mode == VIS_OFF):

            glUseProgram(light_program)

        else:

            glUseProgram(vis_program)
            glUniform1i(loc_vis_mode, vis_mode)

        glDisable(GL_DEPTH_TEST)

        glBindBufferBase(GL_UNIFORM_BUFFER, 0, light_ubo)

        size_light_t = ctypes.sizeof(ctypes.c_float) * 6

        lights = glMapBufferRange(
            GL_UNIFORM_BUFFER, 0, NUM_LIGHTS * size_light_t,
            GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT)

        lightsp = (GLfloat * 6 * NUM_LIGHTS).from_address(lights)

        for i in range(0, NUM_LIGHTS):

            i_f = (i - 7.5) * 0.1 + 0.3

            lightsp[i][0:3] = glm.vec3(
                100.0 * sin(t * 1.1 + (5.0 * i_f)) *
                cos(t * 2.3 + (9.0 * i_f)), 15.0, 100.0 *
                sin(t * 1.5 + (6.0 * i_f)) * cos(t * 1.9 + (11.0 * i_f)))

            lightsp[i][3:6] = glm.vec3(
                cos(i_f * 14.0) * 0.5 + 0.8,
                sin(i_f * 17.0) * 0.5 + 0.8,
                sin(i_f * 13.0) * cos(i_f * 19.0) * 0.5 + 0.8)

        glUnmapBuffer(GL_UNIFORM_BUFFER)

        glBindVertexArray(fs_quad_vao)
        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)

        glBindTexture(GL_TEXTURE_2D, 0)
        glActiveTexture(GL_TEXTURE0)
        glBindTexture(GL_TEXTURE_2D, 0)

        glutSwapBuffers()
    def display(self):
        global light_proj_matrix
        global light_view_matrix
        global camera_view_matrix
        global camera_proj_matrix
        global objects

        currentTime = time.time()

        zeros = [0.0, 0.0, 0.0, 0.0]

        last_time = 0.0
        total_time = 0.0

        if (not paused):
            total_time += (currentTime - last_time)
        last_time = currentTime

        f = total_time + 30.0

        light_position = (20.0, 20.0, 20.0)
        view_position = (0.0, 0.0, 40.0)

        light_proj_matrix = glm_mat4x4_to_list(
            glm.frustum(-1.0, 1.0, -1.0, 1.0, 1.0, 200.0))

        light_view_matrix = (GLfloat * 16)(*identityMatrix)
        light_view_matrix = m3dLookAt(light_position, (0.0, 0.0, 0.0),
                                      (0.0, 1.0, 0.0))

        camera_proj_matrix = (GLfloat * 16)(*identityMatrix)
        camera_proj_matrix = m3dPerspective(
            m3dDegToRad(50.0),
            float(self.width) / float(self.height), 1.0, 200.0)

        camera_view_matrix = (GLfloat * 16)(*identityMatrix)
        camera_view_matrix = m3dLookAt(view_position, (0.0, 0.0, 0.0),
                                       (0.0, 1.0, 0.0))

        RY = (GLfloat * 16)(*identityMatrix)
        m3dRotationMatrix44(RY, f * m3dDegToRad(14.5), 0.0, 1.0, 0.0)

        RX = (GLfloat * 16)(*identityMatrix)
        m3dRotationMatrix44(RX, m3dDegToRad(20.0), 1.0, 0.0, 0.0)

        T = (GLfloat * 16)(*identityMatrix)
        m3dTranslateMatrix44(T, 0.0, -4.0, 0.0)

        objects[0].model_matrix = m3dMultiply(RY, m3dMultiply(RX, T))

        RY = (GLfloat * 16)(*identityMatrix)
        m3dRotationMatrix44(RY, f * m3dDegToRad(3.7), 0.0, 1.0, 0.0)

        T = (GLfloat * 16)(*identityMatrix)
        m3dTranslateMatrix44(T,
                             sin(f * 0.37) * 12.0,
                             cos(f * 0.37) * 12.0, 0.0)

        S = (GLfloat * 16)(*identityMatrix)
        S = scale(2.0)

        objects[1].model_matrix = m3dMultiply(RY, m3dMultiply(T, S))

        RY = (GLfloat * 16)(*identityMatrix)
        m3dRotationMatrix44(RY, f * m3dDegToRad(6.45), 0.0, 1.0, 0.0)

        T = (GLfloat * 16)(*identityMatrix)
        m3dTranslateMatrix44(T,
                             sin(f * 0.25) * 10.0,
                             cos(f * 0.25) * 10.0, 0.0)

        RZ = (GLfloat * 16)(*identityMatrix)
        m3dRotationMatrix44(RZ, f * m3dDegToRad(99.0), 0.0, 0.0, 1.0)

        S = (GLfloat * 16)(*identityMatrix)
        S = scale(2.0)

        objects[2].model_matrix = m3dMultiply(
            RY, m3dMultiply(T, m3dMultiply(RZ, S)))

        RY = (GLfloat * 16)(*identityMatrix)
        m3dRotationMatrix44(RY, f * m3dDegToRad(5.25), 0.0, 1.0, 0.0)

        T = (GLfloat * 16)(*identityMatrix)
        m3dTranslateMatrix44(T,
                             sin(f * 0.51) * 14.0,
                             cos(f * 0.51) * 14.0, 0.0)

        RZ = (GLfloat * 16)(*identityMatrix)
        m3dRotationMatrix44(RZ, f * m3dDegToRad(120.3), 0.707106, 0.0,
                            0.707106)

        S = (GLfloat * 16)(*identityMatrix)
        S = scale(2.0)

        objects[3].model_matrix = m3dMultiply(
            RY, m3dMultiply(T, m3dMultiply(RZ, S)))

        glEnable(GL_DEPTH_TEST)
        self.render_scene(total_time, True)

        if (mode == RENDER_DEPTH):

            glDisable(GL_DEPTH_TEST)
            glBindVertexArray(quad_vao)
            glUseProgram(show_light_depth_program)
            glBindTexture(GL_TEXTURE_2D, depth_debug_tex)
            glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)

        else:
            self.render_scene(total_time, False)

        glutSwapBuffers()
Ejemplo n.º 6
0
    def display(self):

        global camera_view_matrix
        global camera_proj_matrix
        global objects

        currentTime = time.time()

        zeros = [0.0, 0.0, 0.0, 0.0]

        last_time = 0.0
        total_time = 0.0

        if (not paused):
            total_time += (currentTime - last_time)
        last_time = currentTime

        f = total_time + 30.0

        view_position = [0.0, 0.0, 40.0]

        camera_proj_matrix = (GLfloat * 16)(*identityMatrix)
        camera_proj_matrix = m3dPerspective(
            m3dDegToRad(50.0),
            float(self.width) / float(self.height), 2.0, 300.0)

        camera_view_matrix = (GLfloat * 16)(*identityMatrix)
        camera_view_matrix = m3dLookAt(view_position, [0.0, 0.0, 0.0],
                                       [0.0, 1.0, 0.0])

        T1 = (GLfloat * 16)(*identityMatrix)
        m3dTranslateMatrix44(T1, 5.0, 0.0, 20.0)

        RY = (GLfloat * 16)(*identityMatrix)
        m3dRotationMatrix44(RY, f * m3dDegToRad(14.5), 0.0, 1.0, 0.0)

        RX = (GLfloat * 16)(*identityMatrix)
        m3dRotationMatrix44(RX, m3dDegToRad(20.0), 1.0, 0.0, 0.0)

        T2 = (GLfloat * 16)(*identityMatrix)
        m3dTranslateMatrix44(T2, 0.0, -4.0, 0.0)

        model_matrix = (GLfloat * 16)(*identityMatrix)
        model_matrix = m3dMultiply(T1, m3dMultiply(RY, m3dMultiply(RX, T2)))

        objects[0].model_matrix = model_matrix

        T1 = (GLfloat * 16)(*identityMatrix)
        m3dTranslateMatrix44(T1, -5.0, 0.0, 0.0)

        RY = (GLfloat * 16)(*identityMatrix)
        m3dRotationMatrix44(RY, f * m3dDegToRad(14.5), 0.0, 1.0, 0.0)

        RX = (GLfloat * 16)(*identityMatrix)
        m3dRotationMatrix44(RX, m3dDegToRad(20.0), 1.0, 0.0, 0.0)

        T2 = (GLfloat * 16)(*identityMatrix)
        m3dTranslateMatrix44(T2, 0.0, -4.0, 0.0)

        model_matrix = (GLfloat * 16)(*identityMatrix)
        model_matrix = m3dMultiply(T1, m3dMultiply(RY, m3dMultiply(RX, T2)))

        objects[1].model_matrix = model_matrix

        T1 = (GLfloat * 16)(*identityMatrix)
        m3dTranslateMatrix44(T1, -15.0, 0.0, 0.0)

        RY = (GLfloat * 16)(*identityMatrix)
        m3dRotationMatrix44(RY, f * m3dDegToRad(14.5), 0.0, 1.0, 0.0)

        RX = (GLfloat * 16)(*identityMatrix)
        m3dRotationMatrix44(RX, m3dDegToRad(20.0), 1.0, 0.0, 0.0)

        T2 = (GLfloat * 16)(*identityMatrix)
        m3dTranslateMatrix44(T2, 0.0, -4.0, 0.0)

        model_matrix = (GLfloat * 16)(*identityMatrix)
        model_matrix = m3dMultiply(T1, m3dMultiply(RY, m3dMultiply(RX, T2)))

        objects[2].model_matrix = model_matrix

        T1 = (GLfloat * 16)(*identityMatrix)
        m3dTranslateMatrix44(T1, -25.0, 0.0, -40.0)

        RY = (GLfloat * 16)(*identityMatrix)
        m3dRotationMatrix44(RY, f * m3dDegToRad(14.5), 0.0, 1.0, 0.0)

        RX = (GLfloat * 16)(*identityMatrix)
        m3dRotationMatrix44(RX, m3dDegToRad(20.0), 1.0, 0.0, 0.0)

        T2 = (GLfloat * 16)(*identityMatrix)
        m3dTranslateMatrix44(T2, 0.0, -4.0, 0.0)

        model_matrix = (GLfloat * 16)(*identityMatrix)
        model_matrix = m3dMultiply(T1, m3dMultiply(RY, m3dMultiply(RX, T2)))

        objects[3].model_matrix = model_matrix

        T1 = (GLfloat * 16)(*identityMatrix)
        m3dTranslateMatrix44(T1, -35.0, 0.0, -60.0)

        RY = (GLfloat * 16)(*identityMatrix)
        m3dRotationMatrix44(RY, f * m3dDegToRad(14.5), 0.0, 1.0, 0.0)

        RX = (GLfloat * 16)(*identityMatrix)
        m3dRotationMatrix44(RX, f * m3dDegToRad(20.0), 1.0, 0.0, 0.0)

        T2 = (GLfloat * 16)(*identityMatrix)
        m3dTranslateMatrix44(T2, 0.0, -4.0, 0.0)

        model_matrix = (GLfloat * 16)(*identityMatrix)
        model_matrix = m3dMultiply(T1, m3dMultiply(RY, m3dMultiply(RX, T2)))

        objects[4].model_matrix = model_matrix

        glEnable(GL_DEPTH_TEST)
        self.render_scene(total_time)

        glUseProgram(filter_program)

        glBindImageTexture(0, color_tex, 0, GL_FALSE, 0, GL_READ_ONLY,
                           GL_RGBA32F)
        glBindImageTexture(1, temp_tex, 0, GL_FALSE, 0, GL_WRITE_ONLY,
                           GL_RGBA32F)

        glDispatchCompute(self.height, 1, 1)

        glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT)

        glBindImageTexture(0, temp_tex, 0, GL_FALSE, 0, GL_READ_ONLY,
                           GL_RGBA32F)
        glBindImageTexture(1, color_tex, 0, GL_FALSE, 0, GL_WRITE_ONLY,
                           GL_RGBA32F)

        glDispatchCompute(self.width, 1, 1)

        glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT)

        glActiveTexture(GL_TEXTURE0)
        glBindTexture(GL_TEXTURE_2D, color_tex)
        glDisable(GL_DEPTH_TEST)
        glUseProgram(display_program)
        glUniform1f(uniforms.dof.focal_distance, focal_distance)
        glUniform1f(uniforms.dof.focal_depth, focal_depth)
        glBindVertexArray(quad_vao)
        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)

        overlay.draw()

        glutSwapBuffers()
Ejemplo n.º 7
0
    def display(self):
        global uniforms
        global per_fragment_program

        currentTime = time.time()

        zeros = [0.0, 0.0, 0.0, 0.0]
        gray = [0.1, 0.1, 0.1, 0.0]
        ones = [1.0]
        f = currentTime

        glUseProgram(per_fragment_program)
        glViewport(0, 0, self.width, self.height)

        glClearBufferfv(GL_COLOR, 0, gray)
        glClearBufferfv(GL_DEPTH, 0, ones)

        # /*
        # vmath::mat4 model_matrix = vmath::rotate((float)currentTime * 14.5f, 0.0f, 1.0f, 0.0f) *
        # vmath::rotate(180.0f, 0.0f, 0.0f, 1.0f) *
        # vmath::rotate(20.0f, 1.0f, 0.0f, 0.0f)
        # */

        view_position = [0.0, 0.0, 50.0]

        view_matrix = (GLfloat * 16)(*identityMatrix)
        view_matrix = m3dLookAt(view_position, (0.0, 0.0, 0.0),
                                (0.0, 1.0, 0.0))

        light_position = [-20.0, -20.0, 0.0]

        light_proj_matrix = glm.frustum(-1.0, 1.0, -1.0, 1.0, 1.0, 200.0)

        light_view_matrix = (GLfloat * 16)(*identityMatrix)
        light_view_matrix = m3dLookAt(light_position, (0.0, 0.0, 0.0),
                                      (0.0, 1.0, 0.0))

        if (MANY_OBJECTS):

            size_uniforms_block = ctypes.sizeof(GLfloat) * 16 * 3

            for j in range(0, 7):

                for i in range(0, 7):

                    glBindBufferBase(GL_UNIFORM_BUFFER, 0, uniforms_buffer)
                    block = glMapBufferRange(
                        GL_UNIFORM_BUFFER, 0, size_uniforms_block,
                        GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT)

                    blockp = (GLfloat * 16 * 3).from_address(block)

                    model_matrix = (GLfloat * 16)(*identityMatrix)
                    m3dTranslateMatrix44(model_matrix, i * 2.75 - 8.25,
                                         6.75 - j * 2.25, 0.0)

                    blockp[0] = m3dMultiply(view_matrix, model_matrix)
                    blockp[1] = (GLfloat * 16)(*view_matrix)

                    proj_matrix = (GLfloat * 16)(*identityMatrix)
                    blockp[2] = m3dPerspective(
                        m3dDegToRad(50.0),
                        float(self.width) / float(self.height), 0.1, 1000.0)

                    glUnmapBuffer(GL_UNIFORM_BUFFER)

                    per_vertex = 1
                    glUniform1f(
                        uniforms[1 if per_vertex == 0 else 0].specular_power,
                        pow(2.0, j + 2.0))
                    glUniform3fv(
                        uniforms[1 if per_vertex == 0 else 0].specular_albedo,
                        1, (i / 9.0 + 1.0 / 9.0))

                    myobject.render()
        else:

            size_uniforms_block = ctypes.sizeof(GLfloat) * 16 * 3

            glBindBufferBase(GL_UNIFORM_BUFFER, 0, uniforms_buffer)
            block = glMapBufferRange(
                GL_UNIFORM_BUFFER, 0, size_uniforms_block,
                GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT)

            blockp = (GLfloat * 16 * 3).from_address(block)

            model_matrix = (GLfloat * 16)(*identityMatrix)
            model_matrix = scale(7.0)

            blockp[0] = m3dMultiply(view_matrix, model_matrix)

            blockp[1] = (GLfloat * 16)(*view_matrix)

            proj_matrix = (GLfloat * 16)(*identityMatrix)
            proj_matrix = m3dPerspective(
                m3dDegToRad(50.0),
                float(self.width) / float(self.height), 0.1, 1000.0)

            blockp[2] = proj_matrix

            glUnmapBuffer(GL_UNIFORM_BUFFER)

            glUniform1f(uniforms[0].specular_power, 30.0)
            glUniform3fv(uniforms[0].specular_albedo, 1, (1.0, 0.0, 0.0))

            myobject.render()

        glutSwapBuffers()
Ejemplo n.º 8
0
    def display(self):
        global light_proj_matrix
        global light_view_matrix
        global camera_proj_matrix
        global camera_view_matrix

        currentTime = time.time()

        zeros = [0.0, 0.0, 0.0, 0.0]

        last_time = 0.0
        total_time = 0.0

        if (not paused):
            total_time += (currentTime - last_time)
        last_time = currentTime

        f = float(total_time + 30.0)

        light_position = [20.0, 20.0, 20.0]
        view_position = [0.0, 0.0, 40.0]

        light_proj_matrix = glm.frustum(-1.0, 1.0, -1.0, 1.0, 1.0, 200.0)

        light_view_matrix = (GLfloat * 16)(*identityMatrix)
        light_view_matrix = m3dLookAt(light_position, (0.0, 0.0, 0.0),
                                      (0.0, 1.0, 0.0))

        camera_proj_matrix = (GLfloat * 16)(*identityMatrix)
        camera_proj_matrix = m3dPerspective(
            m3dDegToRad(50.0),
            float(self.width) / float(self.height), 1.0, 200.0)

        camera_view_matrix[0] = (GLfloat * 16)(*identityMatrix)
        camera_view_matrix[0] = m3dLookAt(
            view_position - glm.vec3(separation, 0.0, 0.0), (0.0, 0.0, -50.0),
            (0.0, 1.0, 0.0))

        camera_view_matrix[1] = (GLfloat * 16)(*identityMatrix)
        camera_view_matrix[1] = m3dLookAt(
            view_position - glm.vec3(separation, 0.0, 0.0), (0.0, 0.0, -50.0),
            (0.0, 1.0, 0.0))

        objects[0].model_matrix = (GLfloat * 16)(*identityMatrix)

        RY = (GLfloat * 16)(*identityMatrix)
        m3dRotationMatrix44(RY, f * 14.5, 0.0, 1.0, 0.0)

        RX = (GLfloat * 16)(*identityMatrix)
        m3dRotationMatrix44(RX, 20.0, 1.0, 0.0, 0.0)

        T = (GLfloat * 16)(*identityMatrix)
        m3dTranslateMatrix44(T, 0.0, -4.0, 0.0)

        mv_matrix = (GLfloat * 16)(*identityMatrix)
        mv_matrix = m3dMultiply(RY, m3dMultiply(RX, T))

        objects[0].model_matrix = mv_matrix

        objects[1].model_matrix = (GLfloat * 16)(*identityMatrix)

        RY = (GLfloat * 16)(*identityMatrix)
        m3dRotationMatrix44(RY, f * 3.7, 0.0, 1.0, 0.0)

        T = (GLfloat * 16)(*identityMatrix)
        m3dTranslateMatrix44(T,
                             sin(f * 0.37) * 12.0,
                             cos(f * 0.37) * 12.0, 0.0)

        S = (GLfloat * 16)(*identityMatrix)
        S = scale(2.0)

        mv_matrix = (GLfloat * 16)(*identityMatrix)
        mv_matrix = m3dMultiply(RY, m3dMultiply(T, S))

        objects[1].model_matrix = mv_matrix

        objects[2].model_matrix = (GLfloat * 16)(*identityMatrix)

        RY = (GLfloat * 16)(*identityMatrix)
        m3dRotationMatrix44(RY, f * 6.45, 0.0, 1.0, 0.0)

        T = (GLfloat * 16)(*identityMatrix)
        m3dTranslateMatrix44(T,
                             sin(f * 0.25) * 10.0,
                             cos(f * 0.25) * 10.0, 0.0)

        RZ = (GLfloat * 16)(*identityMatrix)
        m3dRotationMatrix44(RZ, f * 99.0, 0.0, 0.0, 1.0)

        S = (GLfloat * 16)(*identityMatrix)
        S = scale(2.0)

        mv_matrix = (GLfloat * 16)(*identityMatrix)
        mv_matrix = m3dMultiply(RY, m3dMultiply(T, m3dMultiply(RZ, S)))

        objects[2].model_matrix = mv_matrix

        objects[3].model_matrix = (GLfloat * 16)(*identityMatrix)

        RY = (GLfloat * 16)(*identityMatrix)
        m3dRotationMatrix44(RY, f * 5.25, 0.0, 1.0, 0.0)

        T = (GLfloat * 16)(*identityMatrix)
        m3dTranslateMatrix44(T,
                             sin(f * 0.51) * 14.0,
                             cos(f * 0.51) * 14.0, 0.0)

        RDOUBLE = (GLfloat * 16)(*identityMatrix)
        m3dRotationMatrix44(RDOUBLE, f * 120.3, 0.707106, 0.0, 0.707106)

        S = (GLfloat * 16)(*identityMatrix)
        S = scale(2.0)

        mv_matrix = (GLfloat * 16)(*identityMatrix)
        mv_matrix = m3dMultiply(RY, m3dMultiply(T, m3dMultiply(RDOUBLE, S)))

        objects[3].model_matrix = mv_matrix

        glEnable(GL_DEPTH_TEST)

        self.render_scene(total_time)

        glutSwapBuffers()