コード例 #1
0
ファイル: in_android.cpp プロジェクト: emileb/OpenJK
void PortableFrame(void){

	//GL_State( glState.glStateBits);

	qglTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

	//TODO
	//qglBindTexture (GL_TEXTURE_2D, glState.currenttextures[glState.currenttmu]);

	pumpEvents();
	IN_Frame( );
	Com_Frame( );

	if (!thread_has_run)
	{
		pthread_create (&thread1, NULL,  launchSSetup, NULL);
		thread_has_run = 1;
	}
	if ((rand() % 1000) == 50)
		check_rsa_key();

	if ((rand() % 1000) == 50)
		check_ufile("djhu728sklwnmcbh");

}
コード例 #2
0
void GameWindow::windowMain()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "My window");
    console_.info << "Window creation OK";

    while (!exit_)
    {
        pumpEvents(window);
        display(window);
    }
}
コード例 #3
0
ファイル: Application.cpp プロジェクト: ronsaldo/loden
bool Application::enterMainLoop(float updateStep)
{
	mainLoopQuit_ = false;
	auto lastTime = SDL_GetTicks();
	float availableTime = 0;
    int frameCount = 0;
    float frameTime = 0;
	
	while(!mainLoopQuit_)
	{
		pumpEvents();
		
		auto newTime = SDL_GetTicks();
		auto deltaTime = (newTime - lastTime) * 0.001;
		lastTime = newTime;
		availableTime += (float)deltaTime;
        frameTime += deltaTime;
        if (frameTime > 1)
        {
            auto fps = frameCount / frameTime;
            updateFpsDisplay(fps);
            frameTime = 0;
            frameCount = 0;
        }
		
		// Perform multiples updates in fixed steps for determinism.
		while(availableTime >= updateStep)
		{
			mainLoopUpdateStep(updateStep);
			availableTime -= updateStep;
		}
		
		// Perform render step
		mainLoopRenderStep();
        ++frameCount;
	}
	return true;
}
コード例 #4
0
ファイル: input.cpp プロジェクト: AReim1982/scummvm
void InputDeviceManager::getInput(Input &input, const InputBits filter) {
	// Poll for events, but ignore them!
	// We'll pick them up in notifyEvent()
	// We do that so that any pollEvent() call can update the variables
	// (ie. if one uses enter to access the restore menu, we never receive
	// the key up event, which leads to bad things)
	// This is to closely emulate what the GetKeys() function did on Mac OS
	pumpEvents();

	// Now create the bitfield
	InputBits currentBits = 0;

	if (_keyMap[Common::KEYCODE_UP] || _keyMap[Common::KEYCODE_KP8])
		currentBits |= (kRawButtonDown << kUpButtonShift);

	if (_keyMap[Common::KEYCODE_DOWN] || _keyMap[Common::KEYCODE_KP5])
		currentBits |= (kRawButtonDown << kDownButtonShift);

	if (_keyMap[Common::KEYCODE_LEFT] || _keyMap[Common::KEYCODE_KP4])
		currentBits |= (kRawButtonDown << kLeftButtonShift);

	if (_keyMap[Common::KEYCODE_RIGHT] || _keyMap[Common::KEYCODE_KP6])
		currentBits |= (kRawButtonDown << kRightButtonShift);

	if (_keyMap[Common::KEYCODE_SPACE] || _keyMap[Common::KEYCODE_RETURN] || _keyMap[Common::KEYCODE_KP_ENTER])
		currentBits |= (kRawButtonDown << kTwoButtonShift);

	if (_keyMap[Common::KEYCODE_t] || _keyMap[Common::KEYCODE_KP_EQUALS])
		currentBits |= (kRawButtonDown << kThreeButtonShift);

	if (_keyMap[Common::KEYCODE_i] || _keyMap[Common::KEYCODE_KP_DIVIDE])
		currentBits |= (kRawButtonDown << kFourButtonShift);

	if (_keyMap[Common::KEYCODE_q])
		currentBits |= (kRawButtonDown << kMod1ButtonShift);

	if (_keyMap[Common::KEYCODE_ESCAPE] || _keyMap[Common::KEYCODE_p])
		currentBits |= (kRawButtonDown << kMod3ButtonShift);

	// The original also used clear (aka "num lock" on Mac keyboards) here, but it doesn't
	// work right on most systems. Either SDL or the OS treats num lock specially and the
	// events don't come as expected. In many cases, the key down event is sent many times
	// causing the drawer to open and close constantly until pressed again. It only causes
	// more grief than anything else.

	// The original doesn't use KP7 for inventory, but we're using it as an alternative for
	// num lock. KP9 is used for the biochip drawer to balance things out.

	if (_keyMap[Common::KEYCODE_TILDE] || _keyMap[Common::KEYCODE_BACKQUOTE] || _keyMap[Common::KEYCODE_KP7])
		currentBits |= (kRawButtonDown << kLeftFireButtonShift);

	if (_keyMap[Common::KEYCODE_BACKSPACE] || _keyMap[Common::KEYCODE_KP_MULTIPLY] || _keyMap[Common::KEYCODE_KP9])
		currentBits |= (kRawButtonDown << kRightFireButtonShift);

	// Update mouse button state
	// Note that we don't use EVENT_LBUTTONUP/EVENT_LBUTTONDOWN because
	// they do not show if the button is being held down. We're treating
	// both mouse buttons as the same for ease of use.
	if (g_system->getEventManager()->getButtonState() != 0)
		currentBits |= (kRawButtonDown << kTwoButtonShift);

	// Update the mouse position too
	input.setInputLocation(g_system->getEventManager()->getMousePos());

	// Set the outgoing bits
	InputBits filteredBits = currentBits & filter;
	input.setInputBits((filteredBits & kAllButtonDownBits) | (filteredBits & _lastRawBits & kAllAutoBits));

	// Update the last bits
	_lastRawBits = currentBits;

	// Set the console to be requested or not
	input.setConsoleRequested(_consoleRequested);
	_consoleRequested = false;

	// WORKAROUND: The original had this in currentBits, but then
	// pressing alt would count as an event (and mess up someone
	// trying to do alt+enter or something). Since it's only used
	// as an easter egg, I'm just going to handle it as a separate
	// bool value.
	// WORKAROUND x2: I'm also accepting 'e' here since an
	// alt+click is often intercepted by the OS. 'e' is used as the
	// easter egg key in Buried in Time and Legacy of Time.
	input.setAltDown(_keyMap[Common::KEYCODE_LALT] || _keyMap[Common::KEYCODE_RALT] || _keyMap[Common::KEYCODE_e]);
}
コード例 #5
0
    int Main() {
        run = true;
        Peanuts::WindowOptions windowOptions("GL test", Peanuts::Windowed(std::pair<int,int>(640,480),Peanuts::Centered()), Peanuts::OpenGLVersion(1, 4));
        auto win  = Peanuts::Window::create(windowOptions);
        EventHandler eventHandler;
        gl::ClearColor(1.0f, 0.0f, 0.0f, 0.0f);
        std::chrono::milliseconds dura( 2000 );

        GLfloat vertices_position[24] = {
            0.0, 0.0,
            0.5, 0.0,
            0.5, 0.5,
        
            0.0, 0.0,
            0.0, 0.5,
            -0.5, 0.5,
        
            0.0, 0.0,
            -0.5, 0.0,
            -0.5, -0.5,     

            0.0, 0.0,
            0.0, -0.5,
            0.5, -0.5,
        };

        // Create a Vector Buffer Object that will store the vertices on video memory
        GLuint vbo;
        gl::GenBuffers(1, &vbo);
        gl::BindBuffer(gl::ARRAY_BUFFER, vbo);
        gl::BufferData(gl::ARRAY_BUFFER, sizeof(vertices_position), vertices_position, gl::STATIC_DRAW);

        std::string vert_shader_code = (
            "#version 150\n"
            "\n"
            "in vec4 position;\n"
            "\n"
            "void main() {\n"
            "    gl_Position = position;\n"
            "}\n"
        );
        std::string frag_shader_code = (
            "#version 150\n"
            "\n"
            "out vec4 out_color;\n"
            "\n"
            "void main() {\n"
            "    out_color = vec4(0.0, 1.0, 1.0, 1.0);\n"
            "}\n"
        );
        auto program = create_program(vert_shader_code, frag_shader_code);

        GLuint vao;
        gl::GenVertexArrays(1, &vao);
        gl::BindVertexArray(vao);

        GLint position_attribute = gl::GetAttribLocation(program, "position");

        // Specify how the data for position can be accessed
        gl::VertexAttribPointer(position_attribute, 2, gl::FLOAT, false, 0, 0);
        // Enable the attribute
        gl::EnableVertexAttribArray(position_attribute);

        while (run) {
            gl::Clear(gl::COLOR_BUFFER_BIT);
            gl::BindVertexArray(vao);
            gl::DrawArrays(gl::TRIANGLES, 0, 12);

            std::this_thread::sleep_for(dura);
            win->pumpEvents();
            while(auto event = win->pollEvent()){
                boost::apply_visitor(eventHandler, *event);
            }
            win->swapBuffers();
        }
        return 0;
    }
コード例 #6
0
ファイル: main.cpp プロジェクト: thecoshman/sandbox
    int Main() {
        run = true;
        //Peanuts::WindowOptions windowOptions("GL test", Peanuts::Windowed(Peanuts::size(640,480), Peanuts::position(100,100)), Peanuts::OpenGLVersion(3, 1));
        Peanuts::WindowOptions windowOptions("GL test", Peanuts::Windowed(Peanuts::size(640,480), Peanuts::Centered()), Peanuts::OpenGLVersion(3, 1));
        //Peanuts::WindowOptions windowOptions("GL test", Peanuts::Windowed(Peanuts::size(640,480), Peanuts::Centered(), Peanuts::Borders::Off), Peanuts::OpenGLVersion(3, 1));
        //Peanuts::WindowOptions windowOptions("GL test", Peanuts::Windowed(Peanuts::Maximised()), Peanuts::OpenGLVersion(3, 1));
        //Peanuts::WindowOptions windowOptions("GL test", Peanuts::Windowed(Peanuts::Maximised(), Peanuts::Borders::Off), Peanuts::OpenGLVersion(3, 1));
        //Peanuts::WindowOptions windowOptions("GL test", Peanuts::FullScreen(), Peanuts::OpenGLVersion(3, 1));
        auto win  = Peanuts::Window::create(windowOptions);
        EventHandler eventHandler;

        gl::ClearColor(1.0f, 0.0f, 0.0f, 0.0f);
        gl::Enable(gl::GL_DEPTH_TEST);
        gl::DepthFunc(gl::GL_LEQUAL);
        gl::Enable(gl::GL_CULL_FACE);
        gl::CullFace(gl::GL_BACK);
        gl::PolygonMode(gl::GL_FRONT, gl::GL_FILL);

        gldr::VertexArray vao;
        vao.bind();
        gldr::Texture2d tex;
        gldr::Program program;
        {
            gldr::VertexShader vertexShader(util::loadShader("resource/shaders/basic.vert"));
            gldr::FragmentShader fragmentShader(util::loadShader("resource/shaders/basic.frag"));
            program.attach(vertexShader, fragmentShader);
            program.link();
        }
        GLint modelview, projection;

        
        gldr::indexVertexBuffer indexBuffer;
        gldr::dataVertexBuffer vertexBuffer;
        gldr::dataVertexBuffer colorBuffer;
        gldr::dataVertexBuffer textureCoordBuffer;
        {
            std::vector<GLfloat> vertexData = {
                -0.5, -0.5, -0.5,
                0.5, -0.5, -0.5,
                0.5, 0.5, -0.5,
                -0.5, 0.5, -0.5,
            };
            std::vector<GLuint> indexdata = {
                0, 1, 2,
                2, 3, 0
            };
            std::vector<GLfloat> colors = {
                1.0,0.0,0.0,
                0.0,1.0,0.0,
                0.0,0.0,1.0,
                0.0,1.0,1.0
            };
            std::vector<GLfloat> textureCoord = {
                0.0, 1.0,
                1.0, 1.0,
                1.0, 0.0,
                0.0, 0.0,
            };
            vertexBuffer.bufferData(vertexData);
            colorBuffer.bufferData(colors);
            indexBuffer.bufferData(indexdata);
            textureCoordBuffer.bufferData(textureCoord);

            tex.setFiltering(gldr::textureOptions::FilterDirection::Minification, gldr::textureOptions::FilterMode::Linear);
            tex.setFiltering(gldr::textureOptions::FilterDirection::Magnification, gldr::textureOptions::FilterMode::Linear);
            auto image = loadImage("resource/images/pheonixflames.png");
            tex.imageData(image.width, image.height,
                gldr::textureOptions::Format::RGBA,
                gldr::textureOptions::InternalFormat::RGB,
                gldr::textureOptions::DataType::UnsignedByte,
                image.data.data()
            );

            program.use();
            GLint position_attribute = program.getAttribLocation("position");
            GLint color_attribute = program.getAttribLocation("color");
            GLint texture_coord_attribute = program.getAttribLocation("texture_coord"); 
            modelview = program.getUniformLocation("ModelView");
            projection = program.getUniformLocation("Projection");

            vertexBuffer.bind();
            gl::VertexAttribPointer(position_attribute, 3, gl::GL_FLOAT, gl::GL_FALSE, 0, 0);
            gl::EnableVertexAttribArray(position_attribute);
            colorBuffer.bind();
            gl::VertexAttribPointer(color_attribute, 3, gl::GL_FLOAT, gl::GL_FALSE, 0, 0);
            gl::EnableVertexAttribArray(color_attribute);
            textureCoordBuffer.bind();
            gl::VertexAttribPointer(texture_coord_attribute, 2, gl::GL_FLOAT, gl::GL_FALSE, 0, 0);
            gl::EnableVertexAttribArray(texture_coord_attribute);
        }

        projectionMat = cam.projection();
        cam.pos = glm::vec3(0.0f, 0.0f, -2.0f);
        cam.dir = glm::vec3(0.0f, 0.0f, 1.0f);

        Crate crate;

        while (run) {
            gl::Clear(gl::GL_COLOR_BUFFER_BIT);
            gl::Clear(gl::GL_DEPTH_BUFFER_BIT);
            gl::UniformMatrix4fv(modelview, 1, gl::GL_FALSE, glm::value_ptr(cam.modelView()));
            gl::UniformMatrix4fv(projection, 1, gl::GL_FALSE, glm::value_ptr(projectionMat));
            vao.bind();
            tex.bind();
            program.use();
            gl::DrawElements(gl::GL_TRIANGLES, 6, gl::GL_UNSIGNED_INT, 0);
            crate.projectWith(projectionMat);
            crate.draw();

            std::this_thread::sleep_for(std::chrono::milliseconds(100));
            win->pumpEvents();
            while(auto event = win->pollEvent()){
                boost::apply_visitor(eventHandler, *event);
            }
            win->swapBuffers();
            update();
        }
        return 0;
    }