示例#1
0
void Batched::DrawQuad(Vector2 pos, Vector2 size, float rotation, Texture& tex, int atl)
{
	int i = atl%64;
	int j = atl/64;
	Rect aa(i/64.0, (j*32.0)/tex.height, 1/64.0, 32.0/tex.height);
	innerDraw(pos, size, rotation, tex, aa);
}
示例#2
0
GLuint DrawSet::_getDisplayList( void *context )
{    
    GLuint dl = _displayList[context];
    if( dl == 0 || _dirtyDisplayList == true )
    {
#if 0
        dl = glGenLists(1);
        glNewList( dl, GL_COMPILE );
        innerDraw(context);
        glEndList();
        _displayList[context] = dl;
        _dirtyDisplayList = false;
#endif
    }
    return dl;
}
示例#3
0
void DrawSet::apply( void *context, const iiMath::matrix4 &viewmat)
{
#if 1
    iiMath::matrix4 mat;
    iiMath::matrix4f fMat;
    if( _matrixSet )
    {
        mat = _matrix * viewmat;
    }
    else
    {
        mat = viewmat;
    }
  //  printf("DrawSet::apply this=%p _stateSet=%p\n", this, _stateSet.get());
    fMat.copy(mat);
    if(_stateSet)
    {
   //     printf("DrawSet::apply\n");
        _stateSet->setStateValue("matrix", iiDraw::StateValue(fMat));
        _stateSet->setStateValue("iiModelViewMatrix", iiDraw::StateValue(_mvMatrix));
        _stateSet->setStateValue("iiProjectionMatrix", iiDraw::StateValue(_projMatrix));
        _stateSet->setStateValue("iiModelViewProjectionMatrix", iiDraw::StateValue(_mvpMatrix));
    }
#endif
#if 1
   // glPushMatrix(); // [
   // glLoadMatrixd( mat.ptr() );


   // if( _drawAsDisplayList )
  //  {
  //      glCallList( _getDisplayList( context ) );
  //  }
  //  else
  //  {
        innerDraw(context);
  //  }

  //  glPopMatrix(); // ]
#endif
}
示例#4
0
// TODO doesn't center the shape properly when width and height are smaller than screen dimensions
void testApp::saveFrameMultiFBO(string filename, int width, int height)
{
	// these dims need to be multiples of screen dimensions, for now
	// making it independent of screen dims would involve 2d float u_scale uniform in shader
	int MAX_FBO_WIDTH = screen_width*2;
	int MAX_FBO_HEIGHT = screen_height*2;

	ofImage output_img;
	output_img.allocate(width, height, OF_IMAGE_COLOR);

	// set the scale -- assume we kept width/height ratio with the screen
	int num_y_axis_fbos = (int)ceilf((float)height / (float)MAX_FBO_HEIGHT);
	float ratio = ((float)height / (float)MAX_FBO_HEIGHT );
	//float ratio = (float)width / (float)screen_width;

	/*double offset_ratio_x = 2.0 / (double)screen_width;
	double offset_ratio_y = 2.0 / (double)screen_height;*/
	double offset_ratio_x = 2.0 / (double)MAX_FBO_WIDTH;
	double offset_ratio_y = 2.0 / (double)MAX_FBO_HEIGHT;

	shader.begin();
	
	shader.setUniform1f("u_scale", ratio);

	ofFbo fbo;
	/*fbo.allocate(screen_width, screen_height); */
	fbo.allocate(MAX_FBO_WIDTH, MAX_FBO_HEIGHT); 

	float x_center = (float)width / (float)MAX_FBO_WIDTH;
	float y_center = (float)height / (float)MAX_FBO_HEIGHT;

	float x =0;
	while (x < width)
	{
		float y = 0;
		while (y < height)
		{
			// set the offset
			/*shader.setUniform2f("u_offset",
				(x - floorf(width /2.0)) * -offset_ratio_x - 1.0,
				(y - floorf(height/2.0)) * -offset_ratio_y - 1.0 );*/
			float frame_x_center = (x/MAX_FBO_WIDTH)*2 + 1;
			float frame_y_center = (y/MAX_FBO_HEIGHT)*2 + 1;
			/*shader.setUniform2f("u_offset",
				((float)num_y_axis_fbos/2.0)-(x/MAX_FBO_WIDTH)*2,
				((float)num_y_axis_fbos/2.0)-(y/MAX_FBO_HEIGHT)*2 );*/
			shader.setUniform2f("u_offset",
				x_center - frame_x_center,
				y_center - frame_y_center );
			
			// start fbo
			fbo.begin();
			glClearColor(0,0,0,1);
			glClear(GL_COLOR_BUFFER_BIT);
			// projection matrix
			glMatrixMode(GL_PROJECTION);
			update_p_matrix(proj_mat, width, height);
			glLoadMatrixf(proj_mat);
			glMatrixMode(GL_MODELVIEW);
			innerDraw();

			// get pixels
			ofImage img_part;
			int fbo_width = std::min((int)(width - x), MAX_FBO_WIDTH);
			int fbo_height = std::min((int)(height - y), MAX_FBO_HEIGHT);

			img_part.allocate(fbo_width, fbo_height, OF_IMAGE_COLOR);
			unsigned char * pixels = img_part.getPixels();
			glReadPixels(0, MAX_FBO_HEIGHT-fbo_height, fbo_width, fbo_height, GL_RGB, GL_UNSIGNED_BYTE, pixels);
			img_part.mirror(true, false);
			img_part.saveImage("part.png"); // debugging : save the image part

			// end fbo
			fbo.end();

			// draw to output_image
			// TODO fid a more efficient way
			for (int i=0; i< fbo_width; i++) {
				for (int j=0; j<fbo_height; j++) {
					output_img.setColor((int)(x) + i,height - fbo_height - (int)(y) + j, 
						img_part.getColor(i, j));
				}
			}

			y += MAX_FBO_HEIGHT;
		}

		x += MAX_FBO_WIDTH;
	}

	output_img.saveImage(filename);

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

	shader.end();

	// reset modelview matrix
	update_p_matrix(proj_mat, screen_width, screen_height);
	glMatrixMode(GL_PROJECTION);
	glLoadMatrixf(proj_mat);
	glMatrixMode(GL_MODELVIEW);

}
示例#5
0
//--------------------------------------------------------------
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;
}
示例#6
0
void Batched::DrawQuad(Vector2 pos, Vector2 size, Texture& tex)
{
	innerDraw(pos, size, 0, tex, Rect(0,0,1,1));
}
示例#7
0
void Batched::DrawQuad(Vector2 pos, Vector2 size, float rotation, Texture& tex)
{
	innerDraw(pos, size, rotation, tex, Rect(0,0,1,1));
}
示例#8
0
void Batched::DrawQuad(glm::vec2 pos, glm::vec2 size, Texture& tex)
{
	innerDraw(pos, size, 0, tex, Rect(0,0,1,1));
}
示例#9
0
void Batched::DrawQuad(glm::vec2 pos, glm::vec2 size, float rotation, Texture& tex)
{
	innerDraw(pos, size, rotation, tex, Rect(0,0,1,1));
}