PDA

View Full Version : Rendering texture



elect
01-09-2012, 04:21 AM
Basically I render to texture, (I can see that if I read with ReadPixel from that what appears is correct) but when I try to bind that texture to a quad, I dont see anything


// init
gl.glEnable(GL2.GL_TEXTURE_2D);

//gl.glGenRenderbuffers(1, textureID, 0);
gl.glGenTextures(1, textureID, 0);
gl.glBindTexture(GL2.GL_TEXTURE_2D, textureID[0]);

// gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_S, GL2.GL_REPEAT);
// gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_T, GL2.GL_REPEAT);
// gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NEAREST);
// gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NEAREST);

// null means reserve texture memory, but texels are undefined
gl.glTexImage2D(GL2.GL_TEXTURE_2D, 0, GL2.GL_RGB, floorWidth, floorHeight,
0, GL2.GL_RGB, GL2.GL_FLOAT, null);

gl.glGenFramebuffers(1, frameBufferID, 0);
gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, frameBufferID[0]);

//Attach 2D texture to this FBO
gl.glFramebufferTexture2D(GL2.GL_FRAMEBUFFER, GL2.GL_COLOR_ATTACHMENT0,
GL2.GL_TEXTURE_2D, textureID[0], 0);

// depth buffer
int[] depthRenderBufferID = new int[1];
gl.glGenRenderbuffers(1, depthRenderBufferID, 0);
gl.glBindRenderbuffer(GL2.GL_RENDERBUFFER, depthRenderBufferID[0]);
gl.glRenderbufferStorage(GL2.GL_RENDERBUFFER, GL2.GL_DEPTH_COMPONENT24,
floorWidth, floorHeight);
gl.glFramebufferRenderbuffer(GL2.GL_FRAMEBUFFER, GL2.GL_DEPTH_ATTACHMENT,
GL2.GL_RENDERBUFFER, depthRenderBufferID[0]);

if(gl.glCheckFramebufferStatus(GL2.GL_FRAMEBUFFER) == GL2.GL_FRAMEBUFFER_COMPLETE)
System.out.println("GL_FRAMEBUFFER_COMPLETE!!");
else
System.out.println("..[censored] ^^");

gl.glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);

// gl.glViewport(0, 0, floorWidth, floorHeight);
// gl.glMatrixMode(GL2.GL_PROJECTION);
// gl.glLoadIdentity();

//gl.glDisable(GL2.GL_TEXTURE_2D);
//gl.glDisable(GL2.GL_BLEND);
gl.glEnable(GL2.GL_DEPTH_TEST);

gl.glColor3f(0.0f, 0.0f, 0.0f);
gl.glBegin(GL2.GL_TRIANGLES);
gl.glVertex3f(1.0f, 1.0f, 0.0f);
gl.glVertex3f(1.0f,-0.5f, 0.0f);
gl.glVertex3f(-1.0f,-1.0f, 0.0f);
gl.glEnd();

//show the back buffer if double buffering was set
gl.glFlush();



// display

gl.glDisable(GL2.GL_LIGHTING);

gl.glColor3f(1.0f, 1.0f, 1.0f);

gl.glBindTexture(GL2.GL_TEXTURE_2D, textureID[0]);

gl.glBegin(GL2.GL_QUADS);
gl.glTexCoord2f(0.0f, 0.0f);
gl.glVertex3f(-a, -a, 0);
gl.glTexCoord2f(0.0f, 1.0f);
gl.glVertex3f(-a, a, 0);
gl.glTexCoord2f(1.0f, 1.0f);
gl.glVertex3f(a, a, 0);
gl.glTexCoord2f(1.0f, 0.0f);
gl.glVertex3f(a, -a, 0);
gl.glEnd();

tksuoran
01-09-2012, 04:38 AM
You have commented out glTexParameter calls which set filtering modes to nearest. Default filter modes require mipmaps, so you should either use filter mode without mipmaps or generate mipmaps.

V-man
01-09-2012, 07:41 AM
This is covered in "common mistakes" page
http://www.opengl.org/wiki/Common_Mistakes#Creating_a_Texture

elect
01-10-2012, 01:14 AM
You have commented out glTexParameter calls which set filtering modes to nearest. Default filter modes require mipmaps, so you should either use filter mode without mipmaps or generate mipmaps.

It worked, thanks


This is covered in "common mistakes" page
http://www.opengl.org/wiki/Common_Mistakes#Creating_a_Texture

Useful link, thanks