Skip to main content
Updating Question
Source Link
dan369
  • 993
  • 1
  • 10
  • 20

Well im just a bit stuck wondering how to draw an item to a texture. Specifically, i'm using;

glDrawArrays(GL_LINE_STRIP, indices[0], indices.size());

Because what i'm drawing via the above function updates every-frame, i'm just totally not sure how to go about drawing what i have to a texture.

Any help is greatly appreciated!

Edit: Well unfortunately my graphics card doesn't support FrameBuffer Objects :/. So i've been trying to get the copy contents from backbuffer method working.

Here's what i currently have;Edit: http://pastebin.com/dJpPt6Pd

And sadlySo i've been trying now for the best part of a couple of hours to get this thing working. Unfortunately all i still get is a white square. Its probably something stupid

Here's my little testing code that i'm doing wrongi have set-up. Just unsure whatWhat it could be?should do is draw a red square at 100, 100. But even this isn't working for me :/.

glViewport(0 , 0, 512, 512); 
    
glPushAttrib(GL_CURRENT_BIT);
glColor4ub(255, 0, 0, 255);
glBindTexture(GL_TEXTURE_2D, Texture);  

glBegin(GL_QUADS);

// Top-left vertex (corner)
glTexCoord2i(0, 0);
glVertex2i(100, 100);

// Bottom-left vertex (corner)
glTexCoord2i(1, 0);
glVertex2i( 100 + 200, 100);

// Bottom-right vertex (corner)
glTexCoord2i(1, 1);
glVertex2i( 100 + 200, 100 + 200);

// Top-right vertex (corner)
glTexCoord2i(0, 1);
glVertex2i(100, 100 + 200);

glEnd();
glPopAttrib();
glLoadIdentity();       

//Copy Our ViewPort To The Texture 
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 0, 0, 512, 512, 0);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);                       
glClear(GL_COLOR_BUFFER_BIT);       
//Reset Viewport
glViewport(0, 0, 768, 480);                                 

glBindTexture (GL_TEXTURE_2D, Texture);
glEnable(GL_TEXTURE_2D);

glBegin(GL_QUADS);

// Top-left vertex (corner)
glTexCoord2i(0, 0);
glVertex2i(0, 0);

// Bottom-left vertex (corner)
glTexCoord2i(1, 0);
glVertex2i( 0 + 512, 0);

// Bottom-right vertex (corner)
glTexCoord2i(1, 1);
glVertex2i( 0 + 512, 0 + 512);

// Top-right vertex (corner)
glTexCoord2i(0, 1);
glVertex2i(0, 0 + 512);

glEnd();
glDisable(GL_TEXTURE_2D);

Screenshot of the current output: enter image description here

Any help is greatly appreciated!

Well im just a bit stuck wondering how to draw an item to a texture. Specifically, i'm using;

glDrawArrays(GL_LINE_STRIP, indices[0], indices.size());

Because what i'm drawing via the above function updates every-frame, i'm just totally not sure how to go about drawing what i have to a texture.

Any help is greatly appreciated!

Edit: Well unfortunately my graphics card doesn't support FrameBuffer Objects :/. So i've been trying to get the copy contents from backbuffer method working.

Here's what i currently have; http://pastebin.com/dJpPt6Pd

And sadly all i get is a white square. Its probably something stupid that i'm doing wrong. Just unsure what it could be?

Well im just a bit stuck wondering how to draw an item to a texture.

Edit: Well unfortunately my graphics card doesn't support FrameBuffer Objects :/. So i've been trying to get the copy contents from backbuffer method working.

Edit: So i've been trying now for the best part of a couple of hours to get this thing working. Unfortunately all i still get is a white square.

Here's my little testing code that i have set-up. What it should do is draw a red square at 100, 100. But even this isn't working for me :/.

glViewport(0 , 0, 512, 512); 
    
glPushAttrib(GL_CURRENT_BIT);
glColor4ub(255, 0, 0, 255);
glBindTexture(GL_TEXTURE_2D, Texture);  

glBegin(GL_QUADS);

// Top-left vertex (corner)
glTexCoord2i(0, 0);
glVertex2i(100, 100);

// Bottom-left vertex (corner)
glTexCoord2i(1, 0);
glVertex2i( 100 + 200, 100);

// Bottom-right vertex (corner)
glTexCoord2i(1, 1);
glVertex2i( 100 + 200, 100 + 200);

// Top-right vertex (corner)
glTexCoord2i(0, 1);
glVertex2i(100, 100 + 200);

glEnd();
glPopAttrib();
glLoadIdentity();       

//Copy Our ViewPort To The Texture 
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 0, 0, 512, 512, 0);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);                       
glClear(GL_COLOR_BUFFER_BIT);       
//Reset Viewport
glViewport(0, 0, 768, 480);                                 

glBindTexture (GL_TEXTURE_2D, Texture);
glEnable(GL_TEXTURE_2D);

glBegin(GL_QUADS);

// Top-left vertex (corner)
glTexCoord2i(0, 0);
glVertex2i(0, 0);

// Bottom-left vertex (corner)
glTexCoord2i(1, 0);
glVertex2i( 0 + 512, 0);

// Bottom-right vertex (corner)
glTexCoord2i(1, 1);
glVertex2i( 0 + 512, 0 + 512);

// Top-right vertex (corner)
glTexCoord2i(0, 1);
glVertex2i(0, 0 + 512);

glEnd();
glDisable(GL_TEXTURE_2D);

Screenshot of the current output: enter image description here

Any help is greatly appreciated!

Updating Question based on new attempts at solution from answer
Source Link
dan369
  • 993
  • 1
  • 10
  • 20

Well im just a bit stuck wondering how to draw an item to a texture. Specifically, i'm using;

glDrawArrays(GL_LINE_STRIP, indices[0], indices.size());

Because what i'm drawing via the above function updates every-frame, i'm just totally not sure how to go about drawing what i have to a texture.

Any help is greatly appreciated!

Edit: Well unfortunately my graphics card doesn't support FrameBuffer Objects :/. So i've been trying to get the copy contents from backbuffer method working.

Here's what i currently have; http://pastebin.com/dJpPt6Pd

And sadly all i get is a white square. Its probably something stupid that i'm doing wrong. Just unsure what it could be?

Well im just a bit stuck wondering how to draw an item to a texture. Specifically, i'm using;

glDrawArrays(GL_LINE_STRIP, indices[0], indices.size());

Because what i'm drawing via the above function updates every-frame, i'm just totally not sure how to go about drawing what i have to a texture.

Any help is greatly appreciated!

Well im just a bit stuck wondering how to draw an item to a texture. Specifically, i'm using;

glDrawArrays(GL_LINE_STRIP, indices[0], indices.size());

Because what i'm drawing via the above function updates every-frame, i'm just totally not sure how to go about drawing what i have to a texture.

Any help is greatly appreciated!

Edit: Well unfortunately my graphics card doesn't support FrameBuffer Objects :/. So i've been trying to get the copy contents from backbuffer method working.

Here's what i currently have; http://pastebin.com/dJpPt6Pd

And sadly all i get is a white square. Its probably something stupid that i'm doing wrong. Just unsure what it could be?

Source Link
dan369
  • 993
  • 1
  • 10
  • 20

OpenGL: Drawing to a texture

Well im just a bit stuck wondering how to draw an item to a texture. Specifically, i'm using;

glDrawArrays(GL_LINE_STRIP, indices[0], indices.size());

Because what i'm drawing via the above function updates every-frame, i'm just totally not sure how to go about drawing what i have to a texture.

Any help is greatly appreciated!