Drawing an array of lines via glDrawArrays to a texture

Hi guys,

So this is my first post, recently i’ve been stuck with the issue of trying to rendering an array of lines to a texture. And for the life of me, i can’t even get a single line to appear. :sorrow:
Currently as testing code i just have one line being rendering, or atleast trying to be rendered. It should be rendering a line from X:0, Y:10 to X: 512, Y: 10.
I’ve never actually rendered anything to a texture before, so im not sure where the problem is. I have to use glCopyTexImage2D as my gpu doesn’t support FBOs.

Below Is My Current Render To Texture Code.

void Lightning::RenderToTexture(int Width, int Height, GLuint TexID)
	// Render Texture

	//Create Vectors
  	vector<Vector2> v_Points; 
	vector<unsigned int> indices;

	//Push Back Our Initial Starting Position
	v_Points.push_back(startPosition);  //X:0, Y:10
	v_Points.push_back(endPosition);    //X:512, Y:10

	//Set Up Indices Based on v_Points size!
	for (unsigned int i = 0; i < v_Points.size(); i++)

	//Draw Line!
	glColor4ub((GLubyte)color.red, (GLubyte)color.blue, (GLubyte)color.green, (GLubyte)color.alpha);

	glVertexPointer(2, GL_FLOAT, 0, &v_Points[0]);
	glDrawArrays(GL_LINE_STRIP, 0, indices.size());


	//Bind Texture
	glBindTexture(GL_TEXTURE_2D, TexID);
	//Pick Up Texture
	glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 512, 512, 0);

	//Clear Scene
	glClearColor(1.0f, 1.0f, 0.0f, 0.0f);

And It’s usage

void Lightning::Draw()
	RenderToTexture(512, 512, bTexture);

	glBindTexture(GL_TEXTURE_2D, bTexture);
	TestDraw(0, 0, 512, 512);  //Simple GL Quad rendering function

And here’s an image of the current output;

As you can see currently all i see is the white quad :confused:. What should be there is a simple red line. I’ve only ever attempted to render to a texture today so i’m totally unsure where i could/am going wrong.
Any help with this issue would be greatly appreciated.


Most likely your texture is incomplete.

Off-topic: I would suggest you to use more modern way to render to a texture. More specifically, use framebuffer objects to render directly to a texture. This way you can avoid the additional copy from the main framebuffer to the texture.