PDA

View Full Version : Render to Texture, Segmentation Fault ...



abominable
09-13-2010, 09:16 AM
Hello everyone.

In my first tutorials, I had created a function for rendering a given 2D texture. The function is the following.


void renderTheTexture(GLfloat* texture, GLuint textureID, int textureSize)
{
glBindTexture(GL_TEXTURE_2D, textureID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureSize, textureSize, 0, GL_RGBA, GL_FLOAT, texture);
glPushMatrix();
glColor3f(1.0f, 1.0f, 1.0f);
glInterleavedArrays(GL_T2F_V3F, 0, texVertices); // Set our Array of elements to be drawn.
glDrawElements(GL_QUADS, 4, GL_UNSIGNED_INT, texIndices); // Draws it.
glPopMatrix();
}


Now I have been trying a FrameBuffer Object and rendering to texture. So I try rendering the image to a texture and then render the texture to the screen. So I changed my function to the following.


void renderTheTexture(GLuint textureID, int textureSize)
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textureID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureSize, textureSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glPushMatrix();
glBegin(GL_QUADS);
glColor3f(1.0f, 1.0f, 1.0f);
glTexCoord2d(0.0, 0.0); glVertex2d(Xstart, Ystart);
glTexCoord2d(1.0, 0.0); glVertex2d(Xend, Ystart);
glTexCoord2d(1.0, 1.0); glVertex2d(Xend, Yend);
glTexCoord2d(0.0, 1.0); glVertex2d(Xstart, Yend);
glEnd();
// glInterleavedArrays(GL_T2F_V3F, 0, texVertices); // Set our Array of elements to be drawn.
// glDrawElements(GL_QUADS, 4, GL_UNSIGNED_INT, texIndices); // Draws it.
glPopMatrix();
glDisable(GL_TEXTURE_2D);
}


The thing is that if I comment out the lines glBegin() - glEnd(), and use the following 2 lines for rendering, I get a Segmentation Fault. The funny thing is that if I include these 2 lines between the glBegin() - glEnd() and comment out only the equivalent glTexCoord/glVertex, I have something rendered in the screen (not what I expect, but no Segm Fault).

Does anyone have any clue, what do I miss here ? Thanx a lot for any help.

Dark Photon
09-13-2010, 05:42 PM
...
glEnd();
// glInterleavedArrays(GL_T2F_V3F, 0, texVertices); // Set our Array of elements to be drawn.
// glDrawElements(GL_QUADS, 4, GL_UNSIGNED_INT, texIndices); // Draws it.

The thing is that if I comment out the lines glBegin() - glEnd(), and use the following 2 lines for rendering, I get a Segmentation Fault.
Let me first caveat this with I've never used this ancient API call for setting up rendering from an interleaved client vtx attib arrays memory block. You can set up interleaved client arrays using the regular gl*Pointer calls using the stride parameter.

However, there seem to be some old refs that say while this API sets up the pointers, you still have to enable and disable the right vtx attrib arrays yourself (i.e. glEnable/DisableClientState, or glEnable/DisableVertexAttribArray if you switch to generic vtx attribs). For instance, this one (http://www.cegui.org.uk/phpBB2/viewtopic.php?f=3&t=4334#p20063)

This seems to run counter to what the man page, but give it a shot.

abominable
09-14-2010, 09:38 AM
Thanx Dark Photon.