Jump to content


Render to Vertexbuffer in OpenGL (HowTo)


20 replies to this topic

#21 michael84

    New Member

  • Members
  • Pip
  • 6 posts

Posted 16 July 2007 - 02:31 PM

hello,
i try to render to a vertexbuffer like you...I try to copy to the PBO and copy to the VBO to render but...nothing happen.
I am not realy good in OpenGL so I am not really surprised...

I used a shader in CG to calculateposition and put the result in a texture.

my function to draw is here :

/* The main drawing function. */

void DrawGLScene()

{

	static bool init=true;


    		glFinish();

    		start = clock();


		bindToText();

		if(init){

			glGenFramebuffersEXT(1, &fb); 

			init=false;

		}

		// bind offscreen framebuffer (that is, skip the window-specific render target)

		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);

		//fbo_points[0] = GFX::NewFloatRectTex(texSize,texSize,0,true);

		// viewport for 1:1 pixel=texture mapping

		glMatrixMode(GL_PROJECTION);

		glLoadIdentity();

		gluOrtho2D(0.0, texSize, 0.0, texSize);

		glMatrixMode(GL_MODELVIEW);

		glLoadIdentity();

		glViewport(0, 0, texSize, texSize);


		performComputation();



		copyFBOtoPBO();

		       


              glBindTexture(target,0);

glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_EXT, target,0, 0);

glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT1_EXT, target,0, 0);

		

       drawVBO();

	

		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

		glFinish();

		end = clock();

		total += (end-start);

		printf("total time = %lf\n",total);

}


I used almsot the same thing that in the tutorial.InitVBO is called in the main

void initVBO(void){

	glGenBuffers(1, &vbo_vertices_handle);

	glBindBuffer(targetVBO, vbo_vertices_handle);

	glBufferData(targetVBO, texSize*texSize*4*sizeof(float),NULL, GL_STREAM_DRAW);


	glBindBuffer(targetVBO, 0); 

}

void copyFBOtoPBO(void){

	glReadBuffer(attachmentpoints[!flag]);

	glBindBuffer(targetVBO, vbo_vertices_handle);

	glReadPixels(0, 0, texSize, texSize, GL_RGBA, GL_FLOAT, 0);


	glReadBuffer(GL_NONE);

	glBindBufferARB(targetVBO, 0 );

}

void drawVBO(void){

	glBindBuffer(targetVBO, vbo_vertices_handle);

	

	glVertexPointer  ( 4, GL_FLOAT,0, BUFFER_OFFSET(0));

	glEnableClientState(GL_VERTEX_ARRAY);


	glColor3f(1, 0, 0);


	glDrawArrays( GL_TRIANGLES, 0,4);


	glDisableClientState(GL_VERTEX_ARRAY);

	glutSwapBuffers();

}


1)something wrong in the algorithme?

2) targetVBO= GL_PIXEL_PACK_BUFFER_EXT, i saw other example with GL_ARRAY_BUFFER...is it better?

3)in glDrawArrays( GL_TRIANGLES, 0,4); I want to display a pyramid with 4 point, should I use GL_POINT ? (in my texture I have the position of the 4 point)





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users