示例#1
0
void mouseButtonCallback( GLFWwindow* _window, int _button,
						  int _action, int _modifiers )
{
	// update mousestate
	if ( _action==GLFW_PRESS     )
	{
		switch ( _button )
		{
		case GLFW_MOUSE_BUTTON_1:
			mousestate_ |= 0x00000001;
			break;
		case GLFW_MOUSE_BUTTON_2:
			mousestate_ |= 0x00000002;
			break;
		case GLFW_MOUSE_BUTTON_3:
			mousestate_ |= 0x00000004;
			break;
		}
	}
	else if ( _action==GLFW_RELEASE )
	{
		switch ( _button )
		{
		case GLFW_MOUSE_BUTTON_1:
			mousestate_ &= ~0x00000001;
			break;
		case GLFW_MOUSE_BUTTON_2:
			mousestate_ &= ~0x00000002;
			break;
		case GLFW_MOUSE_BUTTON_3:
			mousestate_ &= ~0x00000004;
			break;
		}
	}


	// function doesn't come with cursor positions
	double x, y;
	glfwGetCursorPos( _window, &x, &y );


	// double click, press down, release
	if ( _action==GLFW_PRESS && ( glfwGetTime() < 0.2 ) )
	{
		glfwSetTime( 0 );
		demo_->mouseDoubleClickFunc( _button, x, y, mousestate_, modifiers_ );
	}
	else if ( _action==GLFW_PRESS )
	{
		glfwSetTime( 0 );
		demo_->mousePressFunc( _button, x, y, mousestate_, modifiers_ );
	}
	else if ( _action==GLFW_RELEASE )
	{
		demo_->mouseReleaseFunc( _button, x, y, mousestate_, modifiers_ );
	}
}
示例#2
0
int main(void)
{
	GLFWwindow* window; //WskaŸnik na obiekt reprezentuj¹cy okno
	std::cout << "lol"<<std::endl;

	glfwSetErrorCallback(error_callback);//Zarejestruj procedurê obs³ugi b³êdów

	if (!glfwInit()) { //Zainicjuj bibliotekê GLFW
		fprintf(stderr, "Nie mo¿na zainicjowaæ GLFW.\n");
		exit(EXIT_FAILURE); 
	}

	window = glfwCreateWindow(700, 700, "OpenGL", NULL, NULL);  //Utwórz okno 500x500 o tytule "OpenGL" i kontekst OpenGL. 

	if (!window) //Je¿eli okna nie uda³o siê utworzyæ, to zamknij program
	{
		glfwTerminate();
		exit(EXIT_FAILURE);
	}

	glfwMakeContextCurrent(window); //Od tego momentu kontekst okna staje siê aktywny i polecenia OpenGL bêd¹ dotyczyæ w³aœnie jego.
	glfwSwapInterval(1); //Czekaj na 1 powrót plamki przed pokazaniem ukrytego bufora
	glfwSetKeyCallback(window, key_callback);

	if (glewInit() != GLEW_OK) { //Zainicjuj bibliotekê GLEW
		fprintf(stderr, "Nie mo¿na zainicjowaæ GLEW.\n");
		exit(EXIT_FAILURE);
	}

	initOpenGLProgram(window); //Operacje inicjuj¹ce

	float angle = 0; //K¹t obrotu torusa
	glfwSetTime(0); //Wyzeruj licznik czasu

	initTargets();

	//G³ówna pêtla
	while (!glfwWindowShouldClose(window)) //Tak d³ugo jak okno nie powinno zostaæ zamkniête
	{
		//std::cout << glfwGetTime()<<std::endl;
		ship.moveCamera(glfwGetTime(), nextMove);
		rotateTargets(glfwGetTime());
		addObjects();
		moveObjects();
		checkForCollision();
		glfwSetTime(0);
		drawScene(window,angle); //Wykonaj procedurê rysuj¹c¹
		glfwPollEvents(); //Wykonaj procedury callback w zaleznoœci od zdarzeñ jakie zasz³y.
		//Wyzeruj licznik czasu
	}

	glfwDestroyWindow(window); //Usuñ kontekst OpenGL i okno
	glfwTerminate(); //Zwolnij zasoby zajête przez GLFW
	exit(EXIT_SUCCESS);
}
示例#3
0
            void getPreviousScene()
            {
                if (sceneList.size() == 1)
                {
                    return;
                }

                double newTime =
                    prepareSwappedScene((currentScene - 1) % sceneList.size());
                glfwSetTime(newTime);

                glfwSetTime(newTime);
            }
示例#4
0
        void Application::runApplication()
        {
            if (mImpl->currentWindow == nullptr)
            {
                WARN_LOG("Cannot run application without a window.");
                return;
            }

            if (mImpl->sceneList.empty())
            {
                WARN_LOG("Cannot run application without a scene.");
                return;
            }

            glfwShowWindow(mImpl->currentWindow);

            int width, height;
            glfwGetFramebufferSize(mImpl->currentWindow, &width, &height);
            mImpl->sceneList[mImpl->currentScene]->screenResizeEvent(
                width, height);

            glfwSetTime(0.0);
            double currentTime;

            while (!glfwWindowShouldClose(mImpl->currentWindow))
            {
                currentTime = glfwGetTime();
                mImpl->sceneList[mImpl->currentScene]->updateScene(currentTime);
                mImpl->sceneList[mImpl->currentScene]->renderScene();

                glfwSwapBuffers(mImpl->currentWindow);
                glfwPollEvents();
            }
        }
示例#5
0
bool Physics::update()
{
    if (Application::update() == false)
    {
        return false;
    }

    Gizmos::clear();
	
	m_physics->update();
	m_physics->addGizmos();

    float dt = (float)glfwGetTime();
    m_delta_time = dt;
    glfwSetTime(0.0);

	timer += m_delta_time;
	
	//rocketEngine();
	collisionDetectionTute();

	m_camera.update(1.0f / 60.0f);


    return true;
}
示例#6
0
文件: boing.c 项目: Bloodknight/glfw
int main( void )
{
   GLFWwindow window;
   int width, height;

   /* Init GLFW */
   if( !glfwInit() )
   {
      fprintf( stderr, "Failed to initialize GLFW\n" );
      exit( EXIT_FAILURE );
   }

   glfwWindowHint(GLFW_DEPTH_BITS, 16);

   window = glfwCreateWindow( 400, 400, GLFW_WINDOWED, "Boing (classic Amiga demo)", NULL );
   if (!window)
   {
       fprintf( stderr, "Failed to open GLFW window\n" );
       glfwTerminate();
       exit( EXIT_FAILURE );
   }

   glfwSetWindowSizeCallback(window, reshape);

   glfwMakeContextCurrent(window);
   glfwSwapInterval( 1 );

   glfwGetWindowSize(window, &width, &height);
   reshape(window, width, height);

   glfwSetInputMode( window, GLFW_STICKY_KEYS, GL_TRUE );
   glfwSetTime( 0.0 );

   init();

   /* Main loop */
   for (;;)
   {
       /* Timing */
       t = glfwGetTime();
       dt = t - t_old;
       t_old = t;

       /* Draw one frame */
       display();

       /* Swap buffers */
       glfwSwapBuffers(window);
       glfwPollEvents();

       /* Check if we are still running */
       if (glfwGetKey( window, GLFW_KEY_ESCAPE ))
           break;
       if (glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
           break;
   }

   glfwTerminate();
   exit( EXIT_SUCCESS );
}
示例#7
0
void EulerScene::keyPressEvent(int key, int scancode, int action, int mods)
{
    UNUSED(scancode);
    UNUSED(mods);

    if (action == GLFW_PRESS)
    {
        switch (key)
        {
        case GLFW_KEY_R:
            mCamera.resetCamera();
            break;

        case GLFW_KEY_C:
            mCube.resetGeometry();
            break;

        case GLFW_KEY_SPACE:
            if (mIsPlaying)
            {
                mLastTime = glfwGetTime();
            }
            else
            {
                glfwSetTime(mLastTime);
                mIsPlaying = !mIsPlaying;
            }

        default:
            break;
        }
    }
}
示例#8
0
int main() {
    if (!glfwInit()) {
        return -1;
    }

    float t = glfwGetTime();
    printf("glfwGetTime() = %f\n", t);

    printf("glfwSetTime(50)\n");
    glfwSetTime(50);

    // Expect time to be slightly greater than what we set
    t = glfwGetTime();
    printf("glfwGetTime() = %f\n", t);

    if (t < 50 + 1e-3) {
        result = 1;
    }

    glfwTerminate();

#ifdef REPORT_RESULT
    REPORT_RESULT(result);
#endif

    return 0;
}
void step()
{
	// Clear to black
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	InputManager::Update();

	// Get delta time since the last frame
	float dt = (float)glfwGetTime();
	glfwSetTime(0.0);

	// Apply a rotation to the teapot if the user presses the right or left arrow keys
	float dTheta = 45.0f * InputManager::rightKey();
	dTheta -= 45.0f * InputManager::leftKey();

	teapot->transform().angularVelocity = glm::angleAxis(dTheta, glm::vec3(0.0f, 1.0f, 0.0f));

	// Update all components
	CameraManager::Update(dt);

	RenderManager::Update(dt);

	teapot->Update(dt);

	// Draw the display list
	RenderManager::Draw();

	// Swap buffers
	glfwSwapBuffers(window);
}
示例#10
0
/** creates our Window */
void initGLFW()
{
    /* Init GLFW */
    if( !glfwInit() )
        exit( EXIT_FAILURE );

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);

    glfwWindow = glfwCreateWindow( WindowWidth, WindowHeight, WindowName.c_str(), NULL, NULL );
    if (!glfwWindow)
    {
        glfwTerminate();
        exit( EXIT_FAILURE );
    }

    glfwMakeContextCurrent(glfwWindow);
    glfwSwapInterval( 0 ); // Turn off vsync for benchmarking.
    std::cout << "[!] Warning, be sure that vsync is disabled in NVidia controller panel." << std::endl;
    std::cout << "[!] Having vsync disabled allows for a little faster frame rate, but allows for screen tearing and possibly disables triple buffering of the driver." << std::endl;

    int width, height;
    glfwGetFramebufferSize(glfwWindow, &width, &height);
    glViewport( 0, 0, (GLsizei)width, (GLsizei)height );

    glfwSetTime( 0.0 );
    glfwSetKeyCallback(glfwWindow, keyCallback);
    glfwSetErrorCallback(errorCallback);
}
示例#11
0
bool Application::CreateApplication(const char* title, int width, int height)
{
    if (!glfwInit())
    {
        assert(false);
        return false;
    }

	glfwWindowHint(GLFW_RESIZABLE, 0);
    window = glfwCreateWindow(width, height, title, nullptr, nullptr);
    if (!window)
    {
        assert(false);
        return false;
    }
    
    glfwSwapInterval(0);    
    glfwSetTime(0);
    
    glfwMakeContextCurrent(window);
	
    this->width = width;
	this->height = height;
    
	return true;
}
示例#12
0
	Init() {
		if(!glfwInit()) {
			std::cerr << "\nCould not initialize glfw!";
			return;
		}

		glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, true);

		if(!glfwOpenWindow(screenSizeX, screenSizeY, 8, 8, 8, 8, 8, 8, GLFW_WINDOW)) {
			std::cerr << "\nCould not open the window!";
			glfwTerminate();
			return;
		}

		glfwSetWindowTitle("Colorful Game of Life");
		glfwSetWindowPos(350, 150);
		glfwSwapInterval(0);
		glfwSetTime(0);

		if(gl3wInit() != 0) {
			std::cerr << "\nCould not initialize gl3w!";
			glfwTerminate();
			return;
		}
	}
示例#13
0
文件: graphics.c 项目: BonsaiDen/luma
bool graphics_update(void(*callback)(const double time), 
                     void(*key_callback)(GLFWwindow* window, int key, 
                                        int scancode, int action, int mods)) {

    double time = 0;
    double offset = 0;

    glfwSetTime(0);
    glfwSetKeyCallback(window, key_callback);

    while (!glfwWindowShouldClose(window)) {

        time += glfwGetTime() - offset;
        offset = glfwGetTime();
        callback(time);

        glfwSwapBuffers(window);
        glfwPollEvents();

    }

    graphics_info("window closed");

    return true;

}
void init()
{
	if (!glfwInit()) exit(EXIT_FAILURE);

	//Create window
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 4);

	glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

	window = glfwCreateWindow(800, 600, "Geometric_Lighting-GLFW", NULL, NULL); // Windowed

	//Activate window
	glfwMakeContextCurrent(window);

	glewExperimental = true;
	glewInit();

	initShaders();

	glfwSetTime(0.0);

	time_t timer;
	time(&timer);
	srand((unsigned int)timer);

	generateTeapot();

	InputManager::Init(window);
	CameraManager::Init(800.0f / 600.0f, 60.0f, 0.1f, 100.0f);

	glEnable(GL_DEPTH_TEST);
}
// ------------------------------------------------------------------- main ---
int main( int argc, char **argv )
{
    GLFWwindow* window;

    glfwSetErrorCallback( error_callback );

    if (!glfwInit( ))
    {
        exit( EXIT_FAILURE );
    }

    glfwWindowHint( GLFW_VISIBLE, GL_TRUE );
    glfwWindowHint( GLFW_RESIZABLE, GL_FALSE );

    window = glfwCreateWindow( 1, 1, "Freetype OpenGL benchmark", NULL, NULL );

    if (!window)
    {
        glfwTerminate( );
        exit( EXIT_FAILURE );
    }

    glfwMakeContextCurrent( window );
    glfwSwapInterval( 0 ); // disable V-SYNC

    glfwSetFramebufferSizeCallback( window, reshape );
    glfwSetWindowRefreshCallback( window, display );
    glfwSetKeyCallback( window, keyboard );

#ifndef __APPLE__
    glewExperimental = GL_TRUE;
    GLenum err = glewInit();
    if (GLEW_OK != err)
    {
        /* Problem: glewInit failed, something is seriously wrong. */
        fprintf( stderr, "Error: %s\n", glewGetErrorString(err) );
        exit( EXIT_FAILURE );
    }
    fprintf( stderr, "Using GLEW %s\n", glewGetString(GLEW_VERSION) );
#endif

    init();

    glfwSetWindowSize( window, 800, 600 );
    glfwShowWindow( window );

    glfwSetTime(0.0);

    while(!glfwWindowShouldClose( window ))
    {
        display( window );
        glfwPollEvents( );
    }

    glfwDestroyWindow( window );
    glfwTerminate( );

    return EXIT_SUCCESS;
}
示例#16
0
void WavingGrass::RunLoop()
{
    glEnable(GL_DEPTH_TEST);
    //glEnable(GL_CULL_FACE);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    
    n = 20; m = 10; w = 20, h = 50;
    mUp = glm::vec3(0, 1, 0);
    mRight = glm::vec3(1, 0, 0);
    
    std::vector<glm::vec3> grass(n*m);
    
    int Z = -50, X = -100;
    for (int i = 0; i < n; ++i, Z+=5) {
        int offset = (i%2==0)?X:(X+10);
        for (int j = 0; j < m; ++j, offset+=w) {
            float x = (2*offset+w)/2;//(offsetX+offsetX+w)/2
            float y = h/2;
            grass[m*i+j] = glm::vec3(x, y, Z); //Quads的中心点
        }
    }
    
    std::vector<GLushort> indices(n*m);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            indices[m*i+j] = j;
        }
    }
    
    glGenBuffers(1, &mVBO);
    glBindBuffer(GL_ARRAY_BUFFER, mVBO);
    glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec3)*grass.size(), &grass[0], GL_STATIC_DRAW);
    
    glGenBuffers(1, &mIBO);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIBO);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort)*indices.size(), &indices[0], GL_STATIC_DRAW);
    
    glGenVertexArrays(1, &mVAO);
    glBindVertexArray(mVAO);
    glEnableVertexAttribArray(0);
    //glEnableVertexAttribArray(1);
    //glEnableVertexAttribArray(2);
    glBindBuffer(GL_ARRAY_BUFFER, mVBO);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3), NULL);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIBO);
    glBindVertexArray(0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
    
    glfwSetTime(0.2);
    while ( !glfwWindowShouldClose(mpWindow) ) {
        OnRender();
        glfwSwapBuffers(mpWindow);
        glfwPollEvents();
    }
    
    glfwTerminate();
}
示例#17
0
// ------------------------------------------------------------------- main ---
int main( int argc, char **argv )
{
    glfwSetErrorCallback( error_callback );
    if (!glfwInit( )) { exit( EXIT_FAILURE ); }

    glfwWindowHint( GLFW_VISIBLE, GL_FALSE );
    glfwWindowHint( GLFW_RESIZABLE, GL_FALSE );
    glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, 4);
    glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    auto window = glfwCreateWindow( 1, 1, argv[0], nullptr, nullptr);

    if (!window) {
        glfwTerminate( );
        exit( EXIT_FAILURE );
    }

    glfwMakeContextCurrent( window );
    glfwSwapInterval( 1 );

    glfwSetFramebufferSizeCallback( window, reshape );
    glfwSetWindowRefreshCallback( window, display );
    glfwSetKeyCallback( window, keyboard );

#ifndef __APPLE__
    glewExperimental = GL_TRUE;
    GLenum err = glewInit();
    if (GLEW_OK != err)
    {
        /* Problem: glewInit failed, something is seriously wrong. */
        fprintf( stderr, "Error: %s\n", glewGetErrorString(err) );
        exit( EXIT_FAILURE );
    }
    fprintf( stderr, "Using GLEW %s\n", glewGetString(GLEW_VERSION) );
#endif

    init();
    fprintf(stderr, "Total time to generate distance map: %fs\n", total_time);
    glfwSetWindowSize( window, 800, 600 );
    glfwShowWindow( window );

    glfwSetTime(0.0);

    while(!glfwWindowShouldClose( window )) {
        display( window );
        glfwPollEvents( );
    }

    glDeleteTextures( 1, &atlas->id );
    atlas->id = 0;
    texture_atlas_delete( atlas );

    glfwDestroyWindow( window );
    glfwTerminate( );

    return EXIT_SUCCESS;
}
示例#18
0
void Render() {
	GLuint VertexArrayID;
	glGenVertexArrays(1, &VertexArrayID);
	glBindVertexArray(VertexArrayID);

	GLuint programID = LoadShaders("vertex.glsl", "fragment.glsl", "geometry.glsl");

	static const GLfloat g_vertex_buffer_data[] = {
		-1.0f, -1.0f, 0.0f,
		 1.0f, -1.0f, 0.0f,
		-1.0f,  1.0f, 0.0f,
		 1.0f,  1.0f, 0.0f,
	};

	GLuint vertexbuffer;
	glGenBuffers(1, &vertexbuffer);
	glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
	glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);



	do {
		glClear(GL_COLOR_BUFFER_BIT);

		glUseProgram(programID);

		glEnableVertexAttribArray(0);
		glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
		glVertexAttribPointer(
			0,		  // The attribute we want to configure
			3,		  // size
			GL_FLOAT, // type
			GL_FALSE, // normalized?
			0,		  // stride
			(void*)0  // array buffer offset
		);

		glUniform1f(glGetUniformLocation(programID, "iGlobalTime"), glfwGetTime());
		glUniform3f(glGetUniformLocation(programID, "iResolution"), window_width, window_height, 0);
		glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

		glDisableVertexAttribArray(0);

		glfwSwapBuffers(window);
		glfwPollEvents();

		double time = glfwGetTime();
		while(!run) glfwPollEvents();
		glfwSetTime(time);
	} while(glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS && !glfwWindowShouldClose(window));



	glDeleteBuffers(1, &vertexbuffer);
	glDeleteVertexArrays(1, &VertexArrayID);
	glDeleteProgram(programID);
}
示例#19
0
JNIEXPORT void JNICALL Java_com_badlogic_jglfw_Glfw_glfwSetTime(JNIEnv* env, jclass clazz, jdouble time) {


//@line:897

		glfwSetTime(time);
	

}
示例#20
0
static int Ltime(lua_State *L) {
    if (!lua_isnoneornil(L, 1)) {
        double time = luaL_checknumber(L, 1);
        glfwSetTime(time);
        return 0;
    }
    lua_pushnumber(L, glfwGetTime());
    return 1;
}
示例#21
0
文件: boing.c 项目: GarrPeter/glfw
int main( void )
{
   GLFWwindow* window;

   /* Init GLFW */
   if( !glfwInit() )
      exit( EXIT_FAILURE );

   window = glfwCreateWindow( 400, 400, "Boing (classic Amiga demo)", NULL, NULL );
   if (!window)
   {
       glfwTerminate();
       exit( EXIT_FAILURE );
   }

   glfwSetWindowAspectRatio(window, 1, 1);

   glfwSetFramebufferSizeCallback(window, reshape);
   glfwSetKeyCallback(window, key_callback);
   glfwSetMouseButtonCallback(window, mouse_button_callback);
   glfwSetCursorPosCallback(window, cursor_position_callback);

   glfwMakeContextCurrent(window);
   gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
   glfwSwapInterval( 1 );

   glfwGetFramebufferSize(window, &width, &height);
   reshape(window, width, height);

   glfwSetTime( 0.0 );

   init();

   /* Main loop */
   for (;;)
   {
       /* Timing */
       t = glfwGetTime();
       dt = t - t_old;
       t_old = t;

       /* Draw one frame */
       display();

       /* Swap buffers */
       glfwSwapBuffers(window);
       glfwPollEvents();

       /* Check if we are still running */
       if (glfwWindowShouldClose(window))
           break;
   }

   glfwTerminate();
   exit( EXIT_SUCCESS );
}
示例#22
0
int main(int argc, char** argv)
{
    int count = 0;

    if (!glfwInit())
    {
        fprintf(stderr, "Failed to initialize GLFW\n");
        exit(1);
    }

    for (;;)
    {
        if (!open_window(640, 480, (count & 1) ? GLFW_FULLSCREEN : GLFW_WINDOW))
        {
            glfwTerminate();
            exit(1);
        }

        glMatrixMode(GL_PROJECTION);
        glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f);
        glMatrixMode(GL_MODELVIEW);

        glClearColor(0.f, 0.f, 0.f, 0.f);
        glColor3f(1.f, 1.f, 1.f);

        glfwSetTime(0.0);

        while (glfwGetTime() < 5.0)
        {
            glClear(GL_COLOR_BUFFER_BIT);

            glPushMatrix();
            glRotatef((GLfloat) glfwGetTime() * 100.f, 0.f, 0.f, 1.f);
            glRectf(-0.5f, -0.5f, 1.f, 1.f);
            glPopMatrix();

            glfwSwapBuffers();

            if (closed)
                close_window();

            if (!glfwGetWindowParam(GLFW_OPENED))
            {
                printf("User closed window\n");

                glfwTerminate();
                exit(0);
            }
        }

        printf("Closing window\n");
        close_window();

        count++;
    }
}
示例#23
0
void engine_endFrame_windows()
{
	// Get last frame's delta time
	engineInstance->deltaTime = glfwGetTime() - engineInstance->lastTime;
	glfwSetTime(0.0);

	// Swap buffers
	glfwSwapBuffers(engineInstance->window);
	glfwPollEvents();
}
main() {
    for(loopVar = 0; loopVar < BALL_RESOLUTION; loopVar++) {
        ballCosines[loopVar] = cos(loopVar * 2 * PI / BALL_RESOLUTION);
        ballSines[loopVar] = sin(loopVar * 2 * PI / BALL_RESOLUTION);
    }
    loadFile();
    glfwInit();
    glfwOpenWindow(WINDOW_WIDTH, WINDOW_HEIGHT, 0, 0, 0, 0, 0, 0, GLFW_WINDOW);
    glFrustum(-1, 1, -WINDOW_HEIGHT / WINDOW_WIDTH, WINDOW_HEIGHT / WINDOW_WIDTH, 1, CAMERA_RANGE);
    for(glfwSetWindowTitle("Camera Demo"); glfwGetWindowParam(GLFW_OPENED) == GL_TRUE; glfwSwapBuffers(), glClear(GL_COLOR_BUFFER_BIT)) {
        if(glfwGetKey('A') == GLFW_PRESS)
            moveBall(-.1,0,0);
        if(glfwGetKey('D') == GLFW_PRESS)
            moveBall(.1,0,0);
        if(glfwGetKey('S') == GLFW_PRESS)
            moveBall(0,-.1,0);
        if(glfwGetKey('W') == GLFW_PRESS)
            moveBall(0,.1,0);
        if(glfwGetKey('Q') == GLFW_PRESS)
            moveBall(0,0,.1);
        if(glfwGetKey('E') == GLFW_PRESS)
            moveBall(0,0,-.1);
        if(glfwGetKey('Z') == GLFW_PRESS)
            moveBall(-xPos,-yPos,-zPos);
        if(glfwGetKey('X') == GLFW_PRESS)
            loadFile();
        physicsStep();
        glPushMatrix();
        glTranslatef(-xCam - xPos, -yCam - yPos, -zCam - zPos);
        glBegin(GL_LINE_LOOP);
        for(loopVar = 0; loopVar < BALL_RESOLUTION; loopVar++)
            glVertex3f(ballCosines[loopVar] + xPos, ballSines[loopVar] + yPos, zPos);
        glEnd();
        glBegin(GL_LINE_LOOP);
        for(loopVar = 0; loopVar < BALL_RESOLUTION; loopVar++)
            glVertex3f(xPos, ballCosines[loopVar] + yPos, ballSines[loopVar] + zPos);
        glEnd();
        glBegin(GL_LINE_LOOP);
        for(loopVar = 0; loopVar < BALL_RESOLUTION; loopVar++)
            glVertex3f(ballSines[loopVar] + xPos, yPos, ballCosines[loopVar] + zPos);
        glEnd();
        glBegin(GL_LINE_STRIP);
        for(loopVar = 0; loopVar < vertexDataSize; loopVar += 3) {
            if(vertices[loopVar] == 0 && vertices[loopVar + 1] == 0 && vertices[loopVar + 2] == 0) {
                glEnd();
                glBegin(GL_LINE_STRIP);
            }
            else
                glVertex3f(vertices[loopVar],vertices[loopVar+1],vertices[loopVar+2]);
        }
        glEnd();
        glPopMatrix();
        for(glfwSetTime(glfwGetTime() - 1 / FPS); glfwGetTime() < 1 / FPS; );
    }
}
示例#25
0
int main( void )
{
   GLFWwindow* window;
   int width, height;

   /* Init GLFW */
   if( !glfwInit() )
      exit( EXIT_FAILURE );

   glfwWindowHint(GLFW_DEPTH_BITS, 16);

   window = glfwCreateWindow( 400, 400, "Boing (classic Amiga demo)", NULL, NULL );
   if (!window)
   {
       glfwTerminate();
       exit( EXIT_FAILURE );
   }

   glfwSetWindowSizeCallback(window, reshape);
   glfwSetKeyCallback(window, key_callback);

   glfwMakeContextCurrent(window);
   glfwSwapInterval( 1 );

   glfwGetWindowSize(window, &width, &height);
   reshape(window, width, height);

   glfwSetTime( 0.0 );

   init();

   /* Main loop */
   for (;;)
   {
       /* Timing */
       t = glfwGetTime();
       dt = t - t_old;
       t_old = t;

       /* Draw one frame */
       display();

       /* Swap buffers */
       glfwSwapBuffers(window);
       glfwPollEvents();

       /* Check if we are still running */
       if (glfwWindowShouldClose(window))
           break;
   }

   glfwTerminate();
   exit( EXIT_SUCCESS );
}
示例#26
0
int main(int argc, char **argv)
{

	srand(time(NULL));
	time(&startTime);
	lastTime = startTime;

	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);

	glutInitWindowPosition(500, 500);
	glutInitWindowSize(800, 600);
	glutCreateWindow("Test");

	glewInit();
	if (!glfwInit())
		exit(EXIT_FAILURE);

	Init();
	if (glewIsSupported("GL_VERSION_3_3"))
	{
		std::cout << "GLEW Version is 3.3\n";
	}
	else
	{
		std::cout << "GLEW 3.3 is not supported\n";
	}
	glEnable(GL_DEPTH_TEST);
	glutIgnoreKeyRepeat(true);

	glutIdleFunc(idleFunction);
	glutDisplayFunc(renderScene);
	glutReshapeFunc(reshapeView);
	glutSpecialFunc(specialKeyPressed);
	glutSpecialUpFunc(specialKeyReleased);
	glutKeyboardFunc(keyPressed);
	glutMotionFunc(mouseDrag);
	glutPassiveMotionFunc(mouseMove);
	glutMouseFunc(mouseClick);
	glutMouseWheelFunc(mouseScroll);

	const unsigned char* version = glGetString(GL_VERSION);
	std::cout << "Using openGL version " << version << std::endl;
	glutFullScreen();           // making the window full screen
	fpsLastTime = 0;
	fpsCurrentTime = 0;
	glfwSetTime(0);

	myfile.open("fps.txt");

	glutMainLoop();
	myfile.close();
	return 0;
}
示例#27
0
unsigned int Timer::Initialize()
{
#ifdef PLATFORM_WINDOWS

	glfwSetTime(0.0);

#endif

	m_startTime = GetCurrentTimeMS();

	return CS_ERR_NONE;
}
示例#28
0
int main(void)
{
    GLFWvidmode mode;

    if (!glfwInit())
    {
        fprintf(stderr, "Failed to initialize GLFW\n");
        exit(1);
    }

    glfwGetDesktopMode(&mode);

    if (!glfwOpenWindow(mode.Width, mode.Height, 0, 0, 0, 0, 0, 0, GLFW_FULLSCREEN))
    {
        glfwTerminate();

        fprintf(stderr, "Failed to open GLFW window\n");
        exit(1);
    }

    glfwSetWindowTitle("Fullscreen Input Detector");
    glfwSetKeyCallback(key_callback);
    glfwSetCharCallback(char_callback);
    glfwSetMousePosCallback(mouse_position_callback);
    glfwSetMouseButtonCallback(mouse_button_callback);
    glfwSetMouseWheelCallback(mouse_wheel_callback);
    glfwSetWindowSizeCallback(window_size_callback);
    glfwSwapInterval(1);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glfwSetTime(0.0);

    running = GL_TRUE;

    while (running)
    {
        glClearColor((GLclampf) fabs(cos(glfwGetTime() * 4.f)), 0, 0, 0);
        glClear(GL_COLOR_BUFFER_BIT);

        glfwSwapBuffers();

        if (!glfwGetWindowParam(GLFW_OPENED))
            running = GL_FALSE;

        if (glfwGetTime() > 10.0)
            running = GL_FALSE;
    }

    glfwTerminate();
    exit(0);
}
示例#29
0
    Impl(That* that)
    : that(that)
    , mainWindow(0)
    , sharingWindow(0)
    {
        if (!glfwInit())
        {
            uplink_log_error("Failed to initialize GLFW.");
            abort();
        }

        mainWindow = glfwCreateWindow(
            initialWindowWidth,
            initialWindowHeight,
            "Uplink",
            0,
            0
        );

        // Create a sharing context with a hidden window in order to allow other threads to upload data independently from the rendering thread.
        sharingWindow = glfwCreateWindow(
            1,
            1,
            "",
            0,
            mainWindow
        );
        glfwHideWindow(sharingWindow);

        glfwSetWindowUserPointer(mainWindow, this);

        glfwSetWindowSizeCallback(mainWindow, resize_callback);
        glfwSetKeyCallback(mainWindow, key_callback);
        glfwSwapInterval(1);
        glfwSetTime(0.0);

        glfwMakeContextCurrent(mainWindow);
     
        glGenTextures(1, &colorTextureId);
        glGenTextures(1, &depthTextureId);
     
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);

        glEnable(GL_TEXTURE_2D);

        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

        glClearColor(0., 0., 0., 0.);

        glfwMakeContextCurrent(0);
    }
示例#30
0
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
    if (action != GLFW_PRESS)
        return;

    switch (key)
    {
        case GLFW_KEY_SPACE:
            glfwSetTime(0.0);
            break;
    }
}