Ejemplo n.º 1
0
    def draw(self, view=None, projection=None, mode=None, shader=None, usemodel=True):
        """
        Draw model.

        :param view:
        :param projection:
        :param mode:
        :param shader:
        :param usemodel:
        :return:
        """
        if not self._enabled:
            return
        if mode is None:
            if self._drawMode is None:
                mode = _GL_POLYGON
            else:
                mode = self._drawMode
        if shader is None:
            if self._shader is None:
                raise Exception('MergedShape shader is not set')
            shader = self._shader
        _glUseProgram(shader.shaderProgram)
        if usemodel and shader.keyModel != '':
            _glUniformMatrix4fv(_glGetUniformLocation(shader.shaderProgram, shader.keyModel), 1, _GL_TRUE, self._model)
        if projection is not None and shader.keyProjection != '':
            _glUniformMatrix4fv(_glGetUniformLocation(shader.shaderProgram, shader.keyProjection), 1, _GL_TRUE,
                                projection)
        if view is not None and shader.keyView != '':
            _glUniformMatrix4fv(_glGetUniformLocation(shader.shaderProgram, shader.keyView), 1, _GL_TRUE, view)
        for i in self._shapes:
            shader.draw_shape(i, mode)
        if self._modelPrev is not None:
            self._model = self._modelPrev
            self._modelPrev = None
Ejemplo n.º 2
0
    def draw(self,
             view,
             projection,
             mode=_GL_TRIANGLES,
             shader=None,
             usemodel=True):
        """
        Draw model.

        :param view:
        :param projection:
        :param mode:
        :param shader:
        :param usemodel:
        :return:
        """
        if not self._enabled:
            return
        if mode is None:
            mode = _GL_POLYGON
        if shader is None:
            if self._shader is None:
                raise Exception('MergedShape shader is not set')
            shader = self._shader
        _glUseProgram(shader.shaderProgram)
        if usemodel:
            _glUniformMatrix4fv(
                _glGetUniformLocation(shader.shaderProgram, 'model'), 1,
                _GL_TRUE, self._model)
        _glUniformMatrix4fv(
            _glGetUniformLocation(shader.shaderProgram, 'projection'), 1,
            _GL_TRUE, projection)
        _glUniformMatrix4fv(
            _glGetUniformLocation(shader.shaderProgram, 'view'), 1, _GL_TRUE,
            view)
        for i in self._shapes:
            shader.drawShape(i, mode)
        if self._modelPrev is not None:
            self._model = self._modelPrev
            self._modelPrev = None
Ejemplo n.º 3
0
    def place(self):
        """
        Place light on engine.

        :return:
        """
        if not self._enabled or self._shader is None:
            return
        _glUseProgram(self._shader.shaderProgram)
        _glUniform3f(
            _glGetUniformLocation(self._shader.shaderProgram, 'lightColor'),
            self._color[0], self._color[1], self._color[2])
        _glUniform3f(
            _glGetUniformLocation(self._shader.shaderProgram, 'lightPos'),
            self._position[0], self._position[1], self._position[2])
        _glUniform1ui(
            _glGetUniformLocation(self._shader.shaderProgram, 'shininess'),
            self._shininess)
        _glUniform1f(
            _glGetUniformLocation(self._shader.shaderProgram,
                                  'constantAttenuation'), self._cAtt)
        _glUniform1f(
            _glGetUniformLocation(self._shader.shaderProgram,
                                  'linearAttenuation'), self._lAtt)
        _glUniform1f(
            _glGetUniformLocation(self._shader.shaderProgram,
                                  'quadraticAttenuation'), self._qAtt)