Ejemplo n.º 1
0
void update(double deltaTime)
{
	cam->update(deltaTime);
	running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED);
	moveFPSCam(deltaTime, 2.0f);

	
}
void RocketLibSystem::EventLoop(RocketLibSystemIdleFunction idle_function)
{
	while (running)
	{
		if( !glfwGetWindowParam( GLFW_OPENED ) )
		{
			running = false;
		}

		idle_function();

		if( !glfwGetWindowParam( GLFW_ACTIVE ) )
		{
            glfwSleep( 0.1 );
		}
	}
}
Ejemplo n.º 3
0
void mainLoop() {
	while( glfwGetWindowParam(GLFW_OPENED) && !glfwGetKey(GLFW_KEY_ESC) ) {
		GLUtils::checkForOpenGLError(__FILE__,__LINE__);
		scene->update(glfwGetTime());
		scene->render();
		glfwSwapBuffers();
	}
}
Ejemplo n.º 4
0
/* do__get_window_param
 *
 * opengl-client.api        type:    Session -> Bool
 * opengl-client-driver.api type:   (Session) -> Bool
 */
static Val   do__get_window_param   (Task* task, Val arg)
{


    int result = glfwGetWindowParam( GLFW_OPENED );

    return  result ? HEAP_TRUE : HEAP_FALSE;
}
Ejemplo n.º 5
0
int main() {
	if(!glfw_init()) return -1;
	opengl_init();
	do {
		display();
	} while(glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS && glfwGetWindowParam( GLFW_OPENED ) );

}
Ejemplo n.º 6
0
void kissSimComputerUpdate()
{
	if(!glfwGetWindowParam(GLFW_OPENED)) return;
	kissSimComputerUpdateDigitals();
	kissSimComputerUpdateAnalogs(ksWindow.simWidth+30, 155, ksWindow.simWidth+157 ,  165,  15);
	kissSimComputerUpdateMotors();
	kissSimComputerDraw();
}
Ejemplo n.º 7
0
void update(double deltaTime)
{
	cam->update(deltaTime);

	running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED);

	tim += deltaTime;
}
Ejemplo n.º 8
0
int main(void)
{
    int i, result;
    Thread threads[] =
    {
        { NULL, "Red", 1.f, 0.f, 0.f, 0 },
        { NULL, "Green", 0.f, 1.f, 0.f, 0 },
        { NULL, "Blue", 0.f, 0.f, 1.f, 0 }
    };
    const int count = sizeof(threads) / sizeof(Thread);

    glfwSetErrorCallback(error_callback);

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

    for (i = 0;  i < count;  i++)
    {
        glfwWindowHint(GLFW_POSITION_X, 200 + 250 * i);
        glfwWindowHint(GLFW_POSITION_Y, 200);
        threads[i].window = glfwCreateWindow(200, 200,
                                             GLFW_WINDOWED,
                                             threads[i].title,
                                             NULL);
        if (!threads[i].window)
        {
            glfwTerminate();
            exit(EXIT_FAILURE);
        }

        if (thrd_create(&threads[i].id, thread_main, threads + i) !=
            thrd_success)
        {
            fprintf(stderr, "Failed to create secondary thread\n");

            glfwTerminate();
            exit(EXIT_FAILURE);
        }
    }

    while (running)
    {
        assert(glfwGetCurrentContext() == NULL);

        glfwWaitEvents();

        for (i = 0;  i < count;  i++)
        {
            if (glfwGetWindowParam(threads[i].window, GLFW_CLOSE_REQUESTED))
                running = GL_FALSE;
        }
    }

    for (i = 0;  i < count;  i++)
        thrd_join(threads[i].id, &result);

    exit(EXIT_SUCCESS);
}
Ejemplo n.º 9
0
int main( void )
{
	srand( static_cast<unsigned int>( time(NULL) ) );
	glm::mat4 MVP;
	std::vector<Human *> humans;

	// GLclass must be construct and init first (before we construct other classes)!
	GLclass glclass(1024, 896);
	glclass.glfw_init();
	glclass.opengl_init();

	World world(glclass, 50);
	Cube cube(glclass.MatrixID);
	for(unsigned int i = 0; i < world.max_humans; i++) 
		humans.push_back(new Human(glclass.MatrixID));

	do{
		glclass.newtime = glfwGetTime();
		world.getCameraCoordinates(
			humans[world.camera_human]->initx,
			humans[world.camera_human]->inity,
			humans[world.camera_human]->rotate,
			humans[world.camera_human]->move,
			humans[world.camera_human]->torsoOffset
		);
		glclass.mouse();

		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glUseProgram(glclass.programID);
		
		// here we draw humans ...
		for(unsigned int i = 0; i < world.max_humans; i++) {
			if(glclass.camera_type != 1 && glclass.camera_type != 2)
				MVP =  world.Camera * glm::rotate(glclass.offset_x, 0.0f, 1.0f, 0.0f);
			else
				MVP =  world.Camera;
			humans[i]->draw(0, 0, MVP);
		}
		// ... here surrounding world
		cube.draw(MVP * glm::translate(0.0f, -6.0f, 0.0f) * glm::scale(350.0f, 350.0f, 350.0f));

		GLdouble frametime = glclass.interframe - (glfwGetTime() - glclass.newtime);
		if(frametime > 0)
			std::this_thread::sleep_for(std::chrono::milliseconds(static_cast<long long>(frametime))); // only cpp11 but is cross-platform

		glfwSwapBuffers();
	} while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS && glfwGetWindowParam( GLFW_OPENED ) ); //end:dowhile

	// tiding
	glDeleteProgram(glclass.programID);
	glDeleteVertexArrays(1, &glclass.VertexArrayID);
	glfwTerminate();

	for(unsigned int i = 0; i < world.max_humans; i++)
		delete humans[i];
		
	return 0;
}
Ejemplo n.º 10
0
int main(int argc, char** argv) {
    int running = GL_TRUE;
    // Initialize GLFW
    if (!glfwInit()) {
        exit(EXIT_FAILURE);
    }

    glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4);
    //    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
    //    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 1);
    //        glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //We don't want the old OpenGL

    // Open an OpenGL window
    if (!glfwOpenWindow(1280, 720, 0, 0, 0, 0, 32, 0, GLFW_WINDOW)) {
        glfwTerminate();
        return EXIT_FAILURE;
    }

    glfwSetWindowTitle("Capivara-GL Test");

    //    glEnable(GL_LINE_SMOOTH);
    //    glEnable(GL_BLEND);
    //    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    //    glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
    //    glLineWidth(1.5f);

    glfwEnable(GLFW_KEY_REPEAT);
    glfwEnable(GLFW_STICKY_KEYS);

    glEnable(GL_MULTISAMPLE);
    glDisable(GL_DEPTH_TEST);

    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

    initComponents();
    glfwSetKeyCallback(keyCallback);
    glfwSetCharCallback(charCallback);
    glfwSetWindowRefreshCallback(display);
    glfwSetWindowSizeCallback(reshape);
    glfwSetMousePosCallback(mousePosition);
    glfwSetMouseButtonCallback(mouseButton);
    //-------------------------------------------------------------------------
    // Main loop
    while (running) {
        display();
        glfwSwapBuffers();

        running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED);
    }
    deleteComponents();

    // Close window and terminate GLFW
    glfwTerminate();
    return EXIT_SUCCESS;
}
Ejemplo n.º 11
0
int main()
{	
	if (!glfwInit())
	{
		std::cout << "GLFW failed to initialize!\n";
	}
	glfwOpenWindow(Width,Height,0,0,0,0,32,0,GLFW_WINDOW);
	if (glewInit() != GLEW_OK)
	{
		std::cout << "GLEW failed to initialize!\n";
	}
	glfwSetWindowTitle("PongOut");
	glViewport(0,0,Width, Height);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0,0,0,0,0,100);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glClearColor(1,0,0,1);
	
	glfwSwapInterval (0);
	
	//Camera.CameraInit(45.0f , Width , Height , Model);   use ortho instead \/
	Camera.CameraInit (Width, Height, glm::mat4 (1.0f));
	
	GLuint vao;
	glGenVertexArrays (1 , &vao);
	glBindVertexArray(vao);
	
	Ball ball;
	ball.Init();
	
	float LastTime = glfwGetTime(); // (for deltatime)
	
	while (true)
	{
		float DeltaTime = glfwGetTime() - LastTime; // Deltatime init
		LastTime = glfwGetTime(); // update for deltatime
	
		glClearColor (0.0f , 0.0f , 0.0f , 1.0f);
		glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
			
		ball.Draw();
		
		std::cout << glGetError() << std::flush; // 1281?
		
		glfwSwapBuffers();

		if (glfwGetKey (GLFW_KEY_ESC) || !glfwGetWindowParam(GLFW_OPENED))
		{
			std::cout << "\nShutdown command. Exiting...\n" << std::flush;
			return 0;
		}
		
		
	}
}
Ejemplo n.º 12
0
void GameOver( void )
{
    // Enable sticky keys
    glfwEnable( GLFW_STICKY_KEYS );

    // Until the user presses ESC or SPACE
    while( !glfwGetKey( GLFW_KEY_ESC ) && !glfwGetKey( ' ' ) &&
           glfwGetWindowParam( GLFW_OPENED ) )
    {
        // Draw display
        UpdateDisplay();

        // Setup projection matrix
        glMatrixMode( GL_PROJECTION );
        glLoadIdentity();
        glOrtho( 0.0f, 1.0f, 1.0f, 0.0f, -1.0f, 1.0f );

        // Setup modelview matrix
        glMatrixMode( GL_MODELVIEW );
        glLoadIdentity();

        // Enable blending
        glEnable( GL_BLEND );

        // Dim background
        glBlendFunc( GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA );
        glColor4f( 0.3f, 0.3f, 0.3f, 0.3f );
        glBegin( GL_QUADS );
          glVertex2f( 0.0f, 0.0f );
          glVertex2f( 1.0f, 0.0f );
          glVertex2f( 1.0f, 1.0f );
          glVertex2f( 0.0f, 1.0f );
        glEnd();

        // Display winner text
        glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_COLOR );
        if( winner == PLAYER1 )
        {
            glColor4f( 1.0f, 0.5f, 0.5f, 1.0f );
            DrawImage( TEX_WINNER1, 0.35f, 0.65f, 0.46f, 0.54f );
        }
        else if( winner == PLAYER2 )
        {
            glColor4f( 0.5f, 1.0f, 0.5f, 1.0f );
            DrawImage( TEX_WINNER2, 0.35f, 0.65f, 0.46f, 0.54f );
        }

        // Disable blending
        glDisable( GL_BLEND );

        // Swap buffers
        glfwSwapBuffers();
    }

    // Disable sticky keys
    glfwDisable( GLFW_STICKY_KEYS );
}
Ejemplo n.º 13
0
GameControl::~GameControl() {
    if (glfwGetWindowParam(GLFW_OPENED)) {
        glDeleteTextures(NUM_TEXTURES, m_textures);
    }

    delete m_grid;
    delete m_tetromino;

}
Ejemplo n.º 14
0
void AppMain() {
    if(!glfwInit())
        throw std::runtime_error("glfwInit failed");
    
    glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
    glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_FALSE);
    
    if(!glfwOpenWindow(SCREEN_SIZE.x, SCREEN_SIZE.y, 8, 8, 8, 8, 0, 0, GLFW_WINDOW))
        throw std::runtime_error("glfwOpenWindow failed. Can your hardware handle OpenGL 3.2?");
    
    glewExperimental = GL_TRUE; //stops glew crashing on OSX :-/
    if(glewInit() != GLEW_OK)
        throw std::runtime_error("glewInit failed");
    
    
    std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl;
    std::cout << "GLSL version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;
    std::cout << "Vendor: " << glGetString(GL_VENDOR) << std::endl;
    std::cout << "Renderer: " << glGetString(GL_RENDERER) << std::endl;
    
    if(!GLEW_VERSION_3_2)
        throw std::runtime_error("OpenGL 3.2 API is not available.");
    
    glfwDisable(GLFW_MOUSE_CURSOR);
    glfwSetMousePos(0,0);
    glfwSetMouseWheel(0);
    
    LoadShaders();
    LoadTriangle();
    
    //intialise the Camera position
    gCamera.setPosition(glm::vec3(0,0,4));
    gCamera.setViewportAspectRatio(SCREEN_SIZE.x / SCREEN_SIZE.y);
    gCamera.setNearAndFarPlanes(0.5, 100.0f);
    Axis = glm::vec3(0,1,0);
    
    //intialise the Light attribute
    gLight.position = glm::vec3(0.0f,0.1f,-0.1f);
    gLight.intensities = glm::vec3(0.8,0.78,1); // white light
    gLight.attenuation = 0.2f;
    gLight.ambientCoefficient = 0.005f;
    
    double lastTime = glfwGetTime();
    while(glfwGetWindowParam(GLFW_OPENED)){
        
        double thisTime = glfwGetTime();
        Update(thisTime - lastTime);
        lastTime  = thisTime;
        Render();
        
    }
    
    glfwTerminate();
}
Ejemplo n.º 15
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++;
    }
}
Ejemplo n.º 16
0
void Loop(){
	mat4 ModelMatrix(1.0f);
	float bgColor[] = { 0.2f, 0.4f, 0.5f };
	
	do{
		glClearColor(bgColor[0], bgColor[1], bgColor[2], 1);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		g_mutex.lock();
		drawHands();
		g_mutex.unlock();
		
		g_text.printText2D(info, 30, 30, 15, 0);
		g_text.printText2D(counter, 370, 500, 100, 0);

		if (g_leapListener.saved){
			int i = next_gesture_id - 1;
			printf("next = %d\ni = %d\n", next_gesture_id, i);
			
			char visible[] = "true";

			std::string varname;
			varname.append(std::to_string(i + 1));
			varname.append(" - Name:");
			TwSetParam(bar2, varname.c_str(), "visible", TW_PARAM_CSTRING, 1, visible);

			varname.clear();
			varname.append(std::to_string(i + 1));
			varname.append(" - ID:");
			TwSetParam(bar2, varname.c_str(), "visible", TW_PARAM_CSTRING, 1, visible);

			varname.clear();
			varname.append(std::to_string(i + 1));
			varname.append(" - Hands:");
			TwSetParam(bar2, varname.c_str(), "visible", TW_PARAM_CSTRING, 1, visible);

			varname.clear();
			varname.append(std::to_string(i + 1));
			varname.append(" - Fingers:");
			TwSetParam(bar2, varname.c_str(), "visible", TW_PARAM_CSTRING, 1, visible);

			varname.clear();
			varname.append(std::to_string(i + 1));
			varname.append(" - sep:");
			TwSetParam(bar2, varname.c_str(), "visible", TW_PARAM_CSTRING, 1, visible);
			
			g_leapListener.saved = false;

		}

		TwDraw();

		glfwSwapBuffers();
	} while (glfwGetKey(GLFW_KEY_ESC) != GLFW_PRESS &&
		glfwGetWindowParam(GLFW_OPENED));
}
Ejemplo n.º 17
0
void update(double deltaTime)
{
	cam->update(deltaTime);
	running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED);
	moveFPSCam(deltaTime, 2.0f);
	if (glfwGetKey('P'))
		cam->setPositon(glm::vec3(0.0f, 10.0f, -500.0f));
	if (glfwGetKey('O'))
		cam->setPositon(glm::vec3(0.0f, 10.0f, -50.0f));
}
Ejemplo n.º 18
0
// framework update and checks if its still running or been closed
bool Application::FrameworkUpdate()
{
	glfwSwapBuffers();
    glfwPollEvents();


	m_bFrameworkClosed = glfwGetWindowParam( GLFW_OPENED );

	return m_bFrameworkClosed;
}
Ejemplo n.º 19
0
void IGame::UpdateWindow()
{
	if (!glfwGetWindowParam(GLFW_OPENED))
	{
		log(LOG_TYPE_DEFAULT, "\n");
		log(LOG_TYPE_DEFAULT, "Window closed, engine shutting down..");
		SetRun(false);
		return;
	}
}
Ejemplo n.º 20
0
void GLFWApp::HandleInput()
{
	isRunning = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED);
	int x = 0;
	int y = 0;
	glfwGetMousePos(&x, &y);
	deltaX = x - midWidth;
	deltaY = y - midHeight;
	glfwSetMousePos(midWidth, midHeight);
}
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; );
    }
}
Ejemplo n.º 22
0
int main(void)
{
    GLFWwindow window;
    int width, height;

    setlocale(LC_ALL, "");

    if (!glfwInit())
    {
        fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
        exit(EXIT_FAILURE);
    }

    printf("Library initialized\n");

    glfwSetWindowSizeCallback(window_size_callback);
    glfwSetWindowCloseCallback(window_close_callback);
    glfwSetWindowRefreshCallback(window_refresh_callback);
    glfwSetWindowFocusCallback(window_focus_callback);
    glfwSetWindowIconifyCallback(window_iconify_callback);
    glfwSetMouseButtonCallback(mouse_button_callback);
    glfwSetCursorPosCallback(cursor_position_callback);
    glfwSetCursorEnterCallback(cursor_enter_callback);
    glfwSetScrollCallback(scroll_callback);
    glfwSetKeyCallback(key_callback);
    glfwSetCharCallback(char_callback);

    window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "Event Linter", NULL);
    if (!window)
    {
        glfwTerminate();

        fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
        exit(EXIT_FAILURE);
    }

    printf("Window opened\n");

    glfwMakeContextCurrent(window);
    glfwSwapInterval(1);

    glfwGetWindowSize(window, &width, &height);
    printf("Window size should be %ix%i\n", width, height);

    printf("Key repeat should be %s\n", keyrepeat ? "enabled" : "disabled");
    printf("System keys should be %s\n", systemkeys ? "enabled" : "disabled");

    printf("Main loop starting\n");

    while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
        glfwWaitEvents();

    glfwTerminate();
    exit(EXIT_SUCCESS);
}
Ejemplo n.º 23
0
bool CGraphicsModule::isWindowOpen() {
    if ( glfwGetKey( GLFW_KEY_ESC ) == GLFW_PRESS ) {
        return false;
    }
    
    if ( !glfwGetWindowParam( GLFW_OPENED ) ) {
        return false;
    }
    
    return true;
}
Ejemplo n.º 24
0
	// Check For Game Loop
	bool GameLoop(){

		// Exit Loop If Window Is Closed
		if (!glfwGetWindowParam (GLFW_OPENED)){
			return false;
		}

		else{
			return true;
		}
	}
Ejemplo n.º 25
0
int main(int argc, char **argv){

  t = 0.;

  glfwInit();

  /* glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); */
  /* glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); */
  /* glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); */

  glfwOpenWindow(500,500,0,0,0,0,0,0,GLFW_WINDOW);

  glfwSetWindowPos(50,100);

  glfwSetWindowTitle("halfshadow triangle");

  createshader();

  glfwSwapInterval(1);

  glClearColor(0.,0.,0.5,1.);	/* blue background */

  create_VBO();

  /* prepare_rectangle(); */

  while(glfwGetWindowParam(GLFW_OPENED)){

    glClear(GL_COLOR_BUFFER_BIT);

    glUseProgram(shader_program);

    univar = sin(4.*t);

    /* this is called after glUseProgram() is called. */
    uniID = glGetUniformLocation(shader_program,"uniID");
    glUniform1f(uniID,univar);

    glUniform3f(glGetUniformLocation(shader_program,"uniform2"),sin(3.*t),sin(t),cos(t));
    int index = glGetAttribLocation(shader_program,"myatr");

    glVertexAttrib3f(index,1.,0.,0.);

    time_evolution_triangle();

    draw_VBO();

    glfwSwapBuffers();
  }

  glfwTerminate();

  return 0;
}
Ejemplo n.º 26
0
void run_loop(
	std::unique_ptr<Example>& example,
	GLuint width,
	GLuint height
)
{
	GLuint mouse_x = width / 2;
	GLuint mouse_y = height / 2;
	os::steady_clock os_clock;
	ExampleClock clock;
	while(true)
	{
		clock.Update(os_clock.seconds());
		if(!example->Continue(clock)) break;
		example->Render(clock);

		glfwSwapBuffers();

		int new_x, new_y;
		glfwGetWindowSize(&new_x, &new_y);
		if((int(width) != new_x) || (int(height) != new_y))
		{
			if(new_x <= 0) new_x = 1;
			if(new_y <= 0) new_y = 1;
			width = GLuint(new_x);
			height = GLuint(new_y);
			example->Reshape(width, height);
		}

		glfwGetMousePos(&new_x, &new_y);
		if((int(mouse_x) != new_x) || (int(mouse_y) != new_y))
		{
			if(new_x <= 0) new_x = 1;
			if(new_y <= 0) new_y = 1;
			mouse_x = GLuint(new_x);
			mouse_y = GLuint(new_y);
			example->MouseMove(
				mouse_x,
				height-
				mouse_y,
				width,
				height
			);
		}

		if(glfwGetKey(GLFW_KEY_ESC))
		{
			glfwCloseWindow();
			break;
		}
		if(!glfwGetWindowParam(GLFW_OPENED))
			break;
	}
}
Ejemplo n.º 27
0
int main(int argc, char* argv[]) {
	// check for lua debugger mode
	if(argc > 1 && strcmp(argv[1], "-d") == 0)
		_debug = 1;

	init(APP_TITLE);

	const char* ln = test_line(0);
	tfont_set_text_buf(0, 0, ln);

	// setup key input
	glfwSetKeyCallback(cb_glfw_key);

	// setup lua
	init_lua();

  // main loop
  while(_run) {
//printf("top of main loop: _run: %d\n", _run);
		// enter lua debugger mode
		if(_debug) {
			_debug = 0;
			debug_enter(L);
			if(!_run)
				break;
		}
		
		// do lua timer tick
		tick();

    glClear(GL_COLOR_BUFFER_BIT);

		lua_draw();

		draw_text();

    report_fps();

    glfwSwapBuffers();

		// error check
		error_check();

		// exit check
//		exit_check(&run);
		if(!glfwGetWindowParam(GLFW_OPENED))
			tf_edit_quit();
 
    fps_inc_frames_drawn();
  }

  glfwTerminate();
  return 0;
}
Ejemplo n.º 28
0
int flextInit(void)
{
  
    int major = glfwGetWindowParam(GLFW_OPENGL_VERSION_MAJOR);
    int minor = glfwGetWindowParam(GLFW_OPENGL_VERSION_MINOR);

    flextLoadOpenGLFunctions();
    
    /* --- Check for minimal version and profile --- */

    if (major * 10 + minor < 20) {
	fprintf(stderr, "Error: OpenGL version 2.0 not supported.\n");
        fprintf(stderr, "       Your version is %d.%d.\n", major, minor);
        fprintf(stderr, "       Try updating your graphics driver.\n");
        return GL_FALSE;
    }


    /* --- Check for extensions --- */

    if (!glfwExtensionSupported("GL_EXT_framebuffer_object")) {
        fprintf(stderr, "Error: OpenGL extension EXT_framebuffer_object not supported.\n");
        fprintf(stderr, "       Try updating your graphics driver.\n");
        return GL_FALSE;
    }

    if (glfwExtensionSupported("GL_ARB_geometry_shader4")) {
        FLEXT_ARB_geometry_shader4 = GL_TRUE;
    }

    if (glfwExtensionSupported("GL_EXT_transform_feedback")) {
        FLEXT_EXT_transform_feedback = GL_TRUE;
    }

    if (glfwExtensionSupported("GL_EXT_texture_filter_anisotropic")) {
        FLEXT_EXT_texture_filter_anisotropic = GL_TRUE;
    }


    return GL_TRUE;
}
Ejemplo n.º 29
0
void OpenGLWindow::Update()
{
	double currentTime = glfwGetTime();
    double elapsedTime = currentTime - mPreviousTime;
    mPreviousTime = currentTime;

	if( glfwGetWindowParam( GLFW_OPENED ) )
    {
		glfwSwapBuffers();
		mGameManager->Update(elapsedTime);
	}
}
Ejemplo n.º 30
0
void GLFWWindow::swapBuffers()
{
	if(!opened)
		return;

	glfwSwapBuffers();

	GL_CHECK();

	if(glfwGetKey(GLFW_KEY_ESC) || !glfwGetWindowParam(GLFW_OPENED))
		close();
}