예제 #1
0
파일: flag.c 프로젝트: jckarter/ch5-flag
static void mouse(int button, int state, int x, int y)
{
    if (button == GLUT_LEFT_BUTTON && state == GLUT_UP) {
        g_resources.eye_offset[0] = 0.0f;
        g_resources.eye_offset[1] = 0.0f;
        update_mv_matrix(g_resources.mv_matrix, g_resources.eye_offset);
    }
}
예제 #2
0
파일: flag.c 프로젝트: jckarter/ch5-flag
static void drag(int x, int y)
{
    float w = (float)g_resources.window_size[0];
    float h = (float)g_resources.window_size[1];
    g_resources.eye_offset[0] = (float)x/w - 0.5f;
    g_resources.eye_offset[1] = -(float)y/h + 0.5f;
    update_mv_matrix(g_resources.mv_matrix, g_resources.eye_offset);
}
예제 #3
0
파일: flag.c 프로젝트: jckarter/ch5-flag
static int make_resources(void)
{
    GLuint vertex_shader, fragment_shader, program;

    g_resources.flag_vertex_array = init_flag_mesh(&g_resources.flag);
    init_background_mesh(&g_resources.background);

    g_resources.flag.texture = make_texture("flag.tga");
    g_resources.background.texture = make_texture("background.tga");

    if (!make_shadow_framebuffer(
        &g_resources.shadowmap_texture,
        &g_resources.shadowmap_framebuffer
    )) {
        return 0;
    }

    if (g_resources.flag.texture == 0 || g_resources.background.texture == 0)
        return 0;

    struct flag_shaders shaders;

    if (!make_flag_programs(&shaders))
        return 0;

    enact_flag_programs(&shaders);

    g_resources.eye_offset[0] = 0.0f;
    g_resources.eye_offset[1] = 0.0f;
    g_resources.window_size[0] = INITIAL_WINDOW_WIDTH;
    g_resources.window_size[1] = INITIAL_WINDOW_HEIGHT;

    g_resources.light_direction[0] =  0.408248;
    g_resources.light_direction[1] = -0.816497;
    g_resources.light_direction[2] =  0.408248;

    update_p_matrix(
        g_resources.p_matrix,
        INITIAL_WINDOW_WIDTH,
        INITIAL_WINDOW_HEIGHT
    );
    update_mv_matrix(g_resources.mv_matrix, g_resources.eye_offset);
    update_shadow_matrix(g_resources.shadow_matrix, g_resources.light_direction);

    return 1;
}
예제 #4
0
파일: testApp.cpp 프로젝트: j-v/of-sketches
//--------------------------------------------------------------
void testApp::draw(){
	

	unsigned long long cur_time = ofGetSystemTime();

	update_p_matrix(proj_mat, screen_width, screen_height);
	update_mv_matrix(mv_mat, 0);
	glMatrixMode(GL_PROJECTION);
	glLoadMatrixf(proj_mat);
	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixf(mv_mat);

	if (!use_easycam) look();
	else easycam.begin();

	glVertexPointer(3,GL_FLOAT,sizeof(GLfloat)*3,(void*)0);
	glEnableClientState(GL_VERTEX_ARRAY);
    
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementBuffer);
    glDrawElements(
		GL_QUADS,
		e_buffer_size, /* count */
		GL_UNSIGNED_INT,
        (void*)0            /* element array buffer offset */
    );
	glDisableClientState(GL_VERTEX_ARRAY);

	// print framerate to stdout every second
	static unsigned long long last_fps_tick = 0;	
	if (cur_time > last_fps_tick + 1000)
	{
		last_fps_tick = cur_time;
		cout <<  ofToString(ofGetFrameRate(), 2) << " fps" << endl;
	}

	GLenum err = glGetError();
	if (err)
	{
		//breakpoint?
		if (false)
		cout << "error" << endl;
	}
	last_time = cur_time;

	if (use_easycam) easycam.end();
}
예제 #5
0
파일: testApp.cpp 프로젝트: j-v/of-sketches
//--------------------------------------------------------------
void testApp::setup(){
	g_element_buffer_data = NULL;
	g_vertex_buffer_data = NULL;

	move_camera = false;
	x_res = 100,
	z_res = 100; // number of *vertices* on x & z axis

	last_time = 0;

	// enable alpha blending
	glEnable( GL_BLEND );
	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

	// Draw in wireframe mode
	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); 

	ofSetLogLevel(OF_LOG_VERBOSE);

	ofBackground(0,0,0);

	// load shaders?

	// Initialize projection and model view matrices
	update_p_matrix(proj_mat, screen_width, screen_height);
	update_mv_matrix(mv_mat, 0);
	glMatrixMode(GL_PROJECTION);
	glLoadMatrixf(proj_mat);
	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixf(mv_mat);

	// init GL buffers
	glGenBuffers(1, &vertexBuffer);
	glGenBuffers(1, &elementBuffer);

	// initialize shape
	shape = SHAPE_PLANE;
	generateWireframe();
	bufferGrid();

	// Easycam allows mouse interaction
	use_easycam=false;
	easycam.setNearClip( 0.0625);
	easycam.setDistance(1.0);
}
예제 #6
0
파일: testApp.cpp 프로젝트: j-v/of-sketches
//--------------------------------------------------------------
void testApp::setup(){
	g_element_buffer_data = NULL;
	g_vertex_buffer_data = NULL;

	move_camera = false;
	x_res = 200,
	z_res = 200; // number of *vertices* on x & z axis

	last_time = 0;
	glDisable(GL_DEPTH_TEST);
	glEnable( GL_BLEND );
	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
	
	ofSetLogLevel(OF_LOG_VERBOSE);

	ofBackground(0,0,0,0);

	shader.load("vertex.glsl", "fragment.glsl");
	vert_3d_attrib = shader.getAttributeLocation("position");
	proj_mat_attrib = shader.getAttributeLocation("u_proj_matrix");
	offset_attrib = shader.getAttributeLocation("u_offset");
	shader.setUniform2f("u_offset", 0.0,0.0);
	
	//shader.begin();
	shader.setUniform1f("u_scale", 1.0);
	update_p_matrix(proj_mat, screen_width, screen_height);
	update_mv_matrix(mv_mat, 0);
	/*shader.setUniformMatrix4f("u_proj_matrix", proj_mat);
	shader.setUniformMatrix4f("u_mv_matrix", mv_mat);*/
	//glMatrixMode(GL_PROJECTION);
	//glLoadMatrixf(proj_mat);
	//glMatrixMode(GL_MODELVIEW);
	//glLoadMatrixf(mv_mat);

	// init GL buffers
	glGenBuffers(1, &vertexBuffer);
	glGenBuffers(1, &elementBuffer);

}
예제 #7
0
파일: testApp.cpp 프로젝트: j-v/of-sketches
//--------------------------------------------------------------
void testApp::draw(){
	static bool mat_init = false;
	if (!mat_init)
	{
		// not sure why this part is necessary as we init'd proj and mv matrices in setup()
		update_p_matrix(proj_mat, screen_width, screen_height);
		update_mv_matrix(mv_mat, 0);
		mat_init = true;
	}

	// Need to push proj and modelview matrices b4 drawing mesh, then pop after, to be able to draw text afterwards
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadMatrixf(proj_mat);
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();

	ofDrawBitmapString("Test", 10,10);
	
	unsigned long long cur_time = ofGetSystemTime();

	
	

	ofDrawBitmapString("Test3", 10,50);


	shader.begin();
	shader.setUniform2f("u_offset", 0.0,0.0);
	shader.setUniform1f("u_scale", 1.0);

	innerDraw();

	shader.end();

	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glPopMatrix();
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);

	// show fps
	string str = "framerate: ";                       
	str += ofToString(ofGetFrameRate(), 2) + "fps"; 
	ofDrawBitmapString(str, 20, 20);
	ofDrawBitmapString("HELLLOO", 40,40);


	//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

	// PROBLEM - using my own low level opengl calls seems to cause a problem with
	// openframeworks own text drawing 
	//string str = "framerate: ";                       
	//str += ofToString(ofGetFrameRate(), 2) + "fps"; 
	//ofDrawBitmapStringHighlight(str, 0, 0);	
	//ofDrawBitmapStringHighlight("Test", 20, 10);

	// instead print framerate to stdout every second
	static unsigned long long last_fps_tick = 0;
	
	if (cur_time > last_fps_tick + 1000)
	{
		last_fps_tick = cur_time;
		cout <<  ofToString(ofGetFrameRate(), 2) << " fps" << endl;
	}

	GLenum err = glGetError();
	if (err)
	{
		//breakpoint?
		if (false)
		cout << "error" << endl;
	}
	last_time = cur_time;
}