Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Drawing an array of lines via glDrawArrays to a texture

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2012
    Posts
    1

    Unhappy 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.
    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.
    Code :
    void Lightning::RenderToTexture(int Width, int Height, GLuint TexID)
     {
    	// Render Texture
    	glEnable(GL_TEXTURE_2D);
    	glEnable(GL_BLEND);
    	glBlendFunc(GL_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
     
    	//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++)
    		indices.push_back(i);
     
    	//Draw Line!
    	glPushAttrib(GL_CURRENT_BIT);
    	glColor4ub((GLubyte)color.red, (GLubyte)color.blue, (GLubyte)color.green, (GLubyte)color.alpha);
    	glLineWidth(lWidth);
    	glEnableClientState(GL_VERTEX_ARRAY);
     
    	glVertexPointer(2, GL_FLOAT, 0, &v_Points[0]);
    	glDrawArrays(GL_LINE_STRIP, 0, indices.size());
     
    	glDisableClientState(GL_VERTEX_ARRAY);
    	glPopAttrib();
    	glLoadIdentity();
     
    	//Bind Texture
    	glBindTexture(GL_TEXTURE_2D, TexID);
    	//Pick Up Texture
    	glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 512, 512, 0);
     
    	//Clear Scene
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    	glClearColor(1.0f, 1.0f, 0.0f, 0.0f);
     }

    And It's usage
    Code :
    void Lightning::Draw()
    {
    	RenderToTexture(512, 512, bTexture);
     
    	///TEST QUAD RENDERING!
    	glBindTexture(GL_TEXTURE_2D, bTexture);
    	TestDraw(0, 0, 512, 512);  //Simple GL Quad rendering function
    }

    And here's an image of the current output;
    Click image for larger version. 

Name:	imageError.jpg 
Views:	25 
Size:	5.9 KB 
ID:	786

    As you can see currently all i see is the white quad . 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.

  2. #2
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    941
    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.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •