Example #1
0
def init(textureImg):
    width = 640
    height = 640
    glfw.Init()
    glfw.OpenWindow(width, height, 8, 8, 8, 0, 24, 0, glfw.WINDOW)
    glfw.SetWindowTitle("glfw mesh")
    glfw.SetWindowSizeCallback(Reshape)
    glfw.SetMouseButtonCallback(MouseHandler)
    glfw.SetKeyCallback(KeyboardHandler)
    glfw.SetWindowCloseCallback(WindowCLose)

    glClearColor(1.0, 1.0, 1.0, 1.0)
    glEnable(GL_DEPTH_TEST)
    glDepthFunc(GL_LEQUAL)

    glEnable(GL_TEXTURE_2D)

    # texture one
    textureHandle = glGenTextures(1)
    glBindTexture(GL_TEXTURE_2D, textureHandle)
    # filter for min and mag texture
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)

    # specify the texture
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, textureImg.size[0],
                 textureImg.size[1], 0, GL_RGB, GL_UNSIGNED_BYTE,
                 PIL2array(textureImg))
    return textureHandle
Example #2
0
def init():
    width = 640
    height = 640
    glfw.Init()
    glfw.OpenWindow(width, height, 8, 8, 8, 0, 24, 0, glfw.WINDOW)
    glfw.SetWindowTitle("glfw line")
    glfw.SetWindowSizeCallback(Reshape)
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glEnable(GL_DEPTH_TEST)
    glDepthFunc(GL_LEQUAL);
    
    glfw.SetMouseButtonCallback(MouseHandler)
    glfw.SetKeyCallback(KeyboardHandler)
    glfw.SetWindowCloseCallback(WindowCLose)
    
    global heightmap, terrain_size
    tmpheightmap = open("heightmap.raw", 'rb').read()
    for c in tmpheightmap:
        heightmap.append(ord(c))
    print heightmap
    terrain_size = int(sqrt(len(heightmap)))
    print terrain_size
    
    if(glFogCoordfEXT):  # test
        print 'ok'
Example #3
0
def GlfwInit():
    width = 640
    height = 640
    glfw.Init()
    glfw.OpenWindow(width, height, 8, 8, 8, 0, 24, 0, glfw.WINDOW)
    glfw.SetWindowTitle("glfw line")
    glfw.SetWindowSizeCallback(Reshape)
    glfw.SetMouseButtonCallback(MouseHandler)
    glfw.SetKeyCallback(KeyboardHandler)
Example #4
0
    def __init__(self, *args, **kwargs):
        deviceConfig = kwargs['dconfig']
        deviceSettings = {
            'instance_code':
            deviceConfig['instance_code'],
            'category_id':
            ioHub.devices.EventConstants.DEVICE_CATERGORIES[
                Joystick.categoryTypeString],
            'type_id':
            ioHub.devices.EventConstants.DEVICE_TYPES[
                Joystick.deviceTypeString],
            'device_class':
            deviceConfig['device_class'],
            'user_label':
            deviceConfig['name'],
            'os_device_code':
            'OS_DEV_CODE_NOT_SET',
            'max_event_buffer_length':
            deviceConfig['event_buffer_length']
        }
        Device.__init__(self, **deviceSettings)
        #ioHub.print2stderr("kwargs: "+str(kwargs))

        self._lastPollTime = None

        if Joystick._joystickGLFWInitialized is False:
            Joystick._joystickGLFWInitialized = True
            glfw.Init()

            for i in xrange(glfw.JOYSTICK_LAST):
                if glfw.GetJoystickParam(i, glfw.PRESENT):
                    Joystick._detectedJoysticks.append(i)

        if 'joystick_index' in kwargs['dconfig']:
            self._jid = kwargs['dconfig']['joystick_index']
            if not glfw.GetJoystickParam(self._jid, glfw.PRESENT):
                raise ioHub.devices.ioDeviceError(
                    self,
                    "Requested joystick ID is not present on the computer: %d"
                    % (deviceSettings['joystick_index']))
            jbuttons = glfw.GetJoystickButtons(self._jid)
            jpositions = glfw.GetJoystickPos(self._jid)
            self._joystickButtonStates = N.copy((jbuttons, jbuttons))
            self._joystickPositionStates = N.copy((jpositions, jpositions))

            #ioHub.print2stderr('Buttons:')
            #ioHub.print2stderr(str(self._jid)+' : '+str(self._joystickButtonStates.shape)+' : '+str(self._joystickButtonStates[0])+' : '+str(len(jbuttons)))

            #ioHub.print2stderr('Positions:')
            #ioHub.print2stderr(str(self._jid)+' : '+str(self._joystickPositionStates.shape)+' : '+str(self._joystickPositionStates[1])+' : '+str(len(jpositions)))
        else:
            raise ioHub.devices.ioDeviceError(
                self,
                "joystick_index must be supplied as an entry in the configuration for this device."
            )
Example #5
0
def init():
    width = 640
    height = 480
    glfw.Init()
    glfw.OpenWindow(width, height, 8, 8, 8, 0, 24, 0, glfw.WINDOW)
    glfw.SetWindowTitle("glfw circle")
    glfw.SetWindowSizeCallback(Reshape)
    glEnable(GL_DEPTH_TEST)
    # set eht projection
    
    # mouse
    glfw.SetMouseButtonCallback(MouseHandler)
    glfw.SetKeyCallback(KeyboardHandler)
Example #6
0
def init():
    width = 640
    height = 480
    glfw.Init()
    glfw.OpenWindow(1440, 900, 8, 8, 8, 0, 24, 0, glfw.FULLSCREEN)
    glfw.SetWindowTitle("full glfw")
    glfw.SetWindowSizeCallback(Reshape)
    glEnable(GL_DEPTH_TEST)
    # set eht projection

    # mouse
    glfw.SetMouseButtonCallback(MouseHandler)
    glfw.SetKeyCallback(KeyboardHandler)
Example #7
0
def init():
    width = 640
    height = 640
    glfw.Init()
    glfw.OpenWindow(width, height, 8, 8, 8, 0, 24, 0, glfw.WINDOW)
    glfw.SetWindowTitle("glfw line")
    glfw.SetWindowSizeCallback(Reshape)
    glfw.SetMouseButtonCallback(MouseHandler)
    glfw.SetKeyCallback(KeyboardHandler)
    glfw.SetWindowCloseCallback(WindowCLose)

    glClearColor(0.0, 0.0, 0.0, 0.0)
    glEnable(GL_DEPTH_TEST)
    glDepthFunc(GL_LEQUAL)
Example #8
0
def init():
    width = 640
    height = 480
    glfw.Init()
    glfw.OpenWindow(width, height, 8, 8, 8, 0, 24, 0, glfw.WINDOW)
    glfw.SetWindowTitle("glfw cube change projection")
    glfw.SetWindowSizeCallback(Reshape)
    glEnable(GL_DEPTH_TEST)
    glDepthFunc(GL_LEQUAL)  # ��ʲô����
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

    glfw.SetMouseButtonCallback(MouseHandler)
    glfw.SetKeyCallback(KeyboardHandler)
    glfw.SetMousePosCallback(MouseMoveHandler)
Example #9
0
    def initialize(self, windowWidth, windowHeight, windowName, antiAliasing, fullScreen, resizable):
        if self.initialized:
            return False

        self.running = True

        glfw.Init()


        if antiAliasing:
            glfw._glfwdll.glfwOpenWindowHint(glfw.FSAA_SAMPLES, 4)

        windowMode = glfw.WINDOW
        if fullScreen:
            windowMode = glfw.FULLSCREEN

        if resizable:
            #glfw.OpenWindowHint(glfw.WINDOW_NO_RESIZE, 0);
            pass

        print(glfw.GetGLVersion())

        glfw.OpenWindow(windowWidth, windowHeight, 0, 0, 0, 8, 0, 0, windowMode)
        glfw.SetWindowTitle(windowName)
        glfw.SetWindowPos(50,50)

        glfw.SwapInterval(1)
        glfw.SetWindowSizeCallback(camera.resize)

        glfw.Disable(glfw.KEY_REPEAT)

        #prevTime = glfw.GetT

        glClearDepth(1.0);
        glPolygonMode(GL_FRONT, GL_FILL)

        glShadeModel(GL_FLAT)

        glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
        glEnable(GL_CULL_FACE)
        glFrontFace(GL_CCW)
        glCullFace(GL_BACK)
        glDepthFunc(GL_LEQUAL)
        glEnable(GL_DEPTH_TEST)
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glClearStencil(0)
        glClearColor(1.0, 1.0, 1.0, 1.0)
Example #10
0
def init():
    width = 1024
    height = 768
    glfw.Init()
    glfw.OpenWindow(width, height, 8, 8, 8, 0, 24, 0, glfw.WINDOW)
    glfw.SetWindowTitle("glfw line")
    glfw.SetWindowSizeCallback(Reshape)
    glClearColor(0.0, 0.0, 0.0, 0.0)
    glEnable(GL_DEPTH_TEST)
    glDepthFunc(GL_LEQUAL)

    glfw.SetMouseButtonCallback(MouseHandler)
    glfw.SetKeyCallback(KeyboardHandler)
    glfw.SetWindowCloseCallback(WindowCLose)

    global m_tga
    m_tga.load("rock.tga")
    m_tga_un.load("opengl_logo_un.tga")
Example #11
0
    def initialize(self):
        glfw.Init()
        glfw.OpenWindowHint(glfw.FSAA_SAMPLES, 4)
        glfw.OpenWindowHint(glfw.OPENGL_VERSION_MAJOR, 3)
        glfw.OpenWindowHint(glfw.OPENGL_VERSION_MINOR, 2)  # 3.2
        glfw.OpenWindowHint(glfw.OPENGL_PROFILE,
                            glfw.OPENGL_CORE_PROFILE)  # 3.2
        glfw.OpenWindowHint(glfw.OPENGL_FORWARD_COMPAT, GL_TRUE)  # 3.2
        glfw.OpenWindowHint(glfw.WINDOW_NO_RESIZE, GL_TRUE)

        try:  # in case we fail to init this version
            glfw.OpenWindow(self.windowWidth, self.windowHeight, 0, 0, 0, 0,
                            24, 8, glfw.WINDOW)
        except Exception as e:
            self.logger.warn("Failed to initialize OpenGL: {}".format(str(e)))
            self.logger.warn("Trying lower version...")
            glfw.OpenWindowHint(glfw.OPENGL_VERSION_MINOR, 0)  # 3.0
            glfw.OpenWindowHint(glfw.OPENGL_PROFILE, 0)  # 3.0
            glfw.OpenWindowHint(glfw.OPENGL_FORWARD_COMPAT, GL_FALSE)  # 3.0
            glfw.OpenWindow(self.windowWidth, self.windowHeight, 0, 0, 0, 0,
                            24, 8, glfw.WINDOW)
            self.logger.warn("OpenGL fallback to lower version worked")

        glfw.SetWindowTitle("TANG")
        glfw.SetWindowCloseCallback(self.onWindowClose)

        glEnable(GL_DEPTH_TEST)
        glEnable(GL_CULL_FACE)

        # Find out OpenGL version, and store for future use
        self.context.GL_version_string = glGetString(GL_VERSION).split(
            ' '
        )[0]  # must have version at the beginning, e.g. "3.0 Mesa 9.x.x" to extract "3.0"
        self.context.GL_version_major, self.context.GL_version_minor = list(
            int(x) for x in self.context.GL_version_string.split('.'))[
                0:2]  # must have only MAJOR.MINOR
        self.logger.info("OpenGL version {}.{}".format(
            self.context.GL_version_major, self.context.GL_version_minor))
        self.context.GLSL_version_string = glGetString(
            GL_SHADING_LANGUAGE_VERSION).split(' ')[0].replace(
                '.', '')  # "1.50" => "150"
        self.logger.info("GLSL version {}".format(
            self.context.GLSL_version_string))
Example #12
0
def init():
    width = 640
    height = 640
    glfw.Init()
    glfw.OpenWindow(width, height, 8, 8, 8, 0, 24, 0, glfw.WINDOW)
    glfw.SetWindowTitle("glfw line")
    glfw.SetWindowSizeCallback(Reshape)
    glClearColor(0.0, 0.0, 0.0, 0.0)
    glEnable(GL_DEPTH_TEST)
    glDepthFunc(GL_LEQUAL)
    # set eht projection

    global m_pDisk
    glfw.SetMouseButtonCallback(MouseHandler)
    glfw.SetKeyCallback(KeyboardHandler)
    m_pDisk = gluNewQuadric()

    if (glBlendColorEXT):
        print "found"
        glBlendColorEXT(0.5, 0.5, 0.5, 0.5)
Example #13
0
def init():
    width = 1024
    height = 768
    glfw.Init()
    glfw.OpenWindow(width, height, 8, 8, 8, 0, 24, 0, glfw.WINDOW)
    glfw.SetWindowTitle("glfw line")
    glfw.SetWindowSizeCallback(Reshape)
    glfw.SetMouseButtonCallback(MouseHandler)
    glfw.SetKeyCallback(KeyboardHandler)
    glfw.SetWindowCloseCallback(WindowCLose)

    glClearColor(0.0, 0.0, 0.0, 0.0)
    glEnable(GL_TEXTURE_2D)

    global texture1, texture2, textureOne, textureTwo
    if (not texture1.load("opengl_logo.tga")):
        exit(0)
    if (not texture2.load("checkerboard.tga")):
        exit(0)

    print texture1.m_width, texture1.m_height

    # texture one
    textureOne = glGenTextures(1)
    glBindTexture(GL_TEXTURE_2D, textureOne)
    # filter for min and mag texture
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)

    # specify the texture
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texture1.m_width, texture1.m_height,
                 0, GL_RGB, GL_UNSIGNED_BYTE, texture1.m_imageData)

    # texure two
    textureTwo = glGenTextures(1)
    glBindTexture(GL_TEXTURE_2D, textureTwo)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texture2.m_width, texture2.m_height,
                 0, GL_RGB, GL_UNSIGNED_BYTE, texture2.m_imageData)
Example #14
0
def initGraphics():
  # * Initialize GLFW and create OpenGL context
  glfw.Init()
  glfw.OpenWindowHint(glfw.FSAA_SAMPLES, 4)
  glfw.OpenWindowHint(glfw.OPENGL_VERSION_MAJOR, 3)
  glfw.OpenWindowHint(glfw.OPENGL_VERSION_MINOR, 2)
  glfw.OpenWindowHint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)
  #glfw.OpenWindowHint(glfw.OPENGL_FORWARD_COMPAT, GL_TRUE)
  glfw.OpenWindowHint(glfw.WINDOW_NO_RESIZE, GL_TRUE)
  glfw.OpenWindow(windowWidth, windowHeight, 0, 0, 0, 0, 0, 0, glfw.WINDOW)
  glfw.SetWindowTitle("GL Camera Viewer".format(OpenGL=glGetString(GL_VERSION), GLSL=glGetString(GL_SHADING_LANGUAGE_VERSION)))
  glfw.Disable(glfw.AUTO_POLL_EVENTS)
  glfw.Enable(glfw.KEY_REPEAT)
  
  logging.info("OpenGL version: %s", glGetString(GL_VERSION))  # glfw.GetGLVersion()
  logging.info("GLSL version  : %s", glGetString(GL_SHADING_LANGUAGE_VERSION))
  logging.info("Renderer      : %s", glGetString(GL_RENDERER))
  logging.info("Vendor        : %s", glGetString(GL_VENDOR))
  logging.info("Window size   : {}x{}".format(windowWidth, windowHeight))
  
  # * Initialize OpenGL parameters
  glClearColor(0.0, 0.0, 0.0, 1.0)
Example #15
0
    def __init__(self, scene):
        """Sets up the core functionality we need
        to begin rendering.
        This includes the OpenGL configuration, the
        window, the viewport, the event handler
        and update loop registration.
        """
        super(Application, self).__init__(scene)

        glfw.Init()

        if self.scene.core_profile:
            glfw.OpenWindowHint(glfw.OPENGL_VERSION_MAJOR, 3)
            glfw.OpenWindowHint(glfw.OPENGL_VERSION_MINOR, 2)
            glfw.OpenWindowHint(glfw.OPENGL_FORWARD_COMPAT, GL.GL_TRUE)
            glfw.OpenWindowHint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)

        # create our window
        glfw.OpenWindow(1024, 768, 8, 8, 8, 8, 24, 0, glfw.WINDOW)

        # set the window caption
        glfw.SetWindowTitle("PyGLy - PyGLFW - " + scene.name)

        # print some opengl information
        pygly.gl.print_gl_info()

        # create the scene now that we've got our window open
        self.scene.initialise()

        self.running = False

        # listen for resize events and close window events
        # do this AFTER initialising the scene
        # as the window size callback will trigger once set
        glfw.SetWindowSizeCallback(self.on_window_resized)
        glfw.SetWindowCloseCallback(self.on_window_closed)
        glfw.SetKeyCallback(self.on_key_event)
Example #16
0
    glLightfv(GL_LIGHT1, GL_DIFFUSE, redLightColor);
    glLightfv(GL_LIGHT1, GL_SPECULAR, redLightColor);
    
    # set up moving green light
    glEnable(GL_LIGHT2);
    glLightfv(GL_LIGHT2, GL_AMBIENT, greenLightColor);
    glLightfv(GL_LIGHT2, GL_DIFFUSE, greenLightColor);
    glLightfv(GL_LIGHT2, GL_SPECULAR, greenLightColor);
    
    # get a quadric object for the light sphere
    m_pSphere = gluNewQuadric()
    
def GlfwInit()
    width = 640
    height = 640
    glfw.Init()
    glfw.OpenWindow(width, height, 8, 8, 8, 0, 24, 0, glfw.WINDOW)
    glfw.SetWindowTitle(glfw line)
    glfw.SetWindowSizeCallback(Reshape)
    glfw.SetMouseButtonCallback(MouseHandler)
    glfw.SetKeyCallback(KeyboardHandler)

def ChangeAngle(dt)
    global CUBE_DEG_PER_S, LIGHT_DEG_PER_S, m_cubeAngle, m_lightAngle
    m_cubeAngle += CUBE_DEG_PER_S  dt;
    if (m_cubeAngle  360.0)
        m_cubeAngle = 0.0;
    m_lightAngle += LIGHT_DEG_PER_S  dt;
    if (m_lightAngle  360.0)
        m_lightAngle = 0.0;