Re: FBO problem
Gernot Ziegler <[email protected]> Wed, 30 Jul 2008 02:20:33 -0800
| Newsgroups | gmane.games.devel.opengl |
|---|---|
| Organization | Fat City Network Services, San Diego, California |
| Message-ID | <[email protected]> |
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
---430484219-2061248159-1217409512=:15420
Content-Type: TEXT/PLAIN; charset=iso-8859-15; format=flowed
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by ns3.fatcity.com id m6UCFgYu022219
Hej,
have you actually used shaders? Float FBOs only work with shaders. Also=20
note that your texture coordinates are different for GL_TEXTURE_RECTANGLE=
=20
in contrast to GL_TEXTURE_2D, but it seems you only use texture rectangle=
=20
anyways.
> I am playing a little bit with FBO. By the way, I am rendering a little=
red
> quad in the middle of the FBO. It works perfect while I use
>=20
> =A0 glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, 4, w, h, 0, GL_RGBA,
> GL_UNSIGNED_BYTE, NULL);
>=20
> yeah...a 8 bits FBO. I can change GL_UNSIGNED_BYTE by GL_FLOAT, and I a=
lways
> get a 8 bits FBO... (well known behaviour).
>=20
> But, If I just change that command by
>=20
> =A0 glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_FLOAT_RGBA16_NV, w, h,
> 0,GL_RGBA, GL_UNSIGNED_SHORT, NULL);
>=20
> or even by
>=20
> =A0 glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_FLOAT_RGBA32_NV, w, h,
> 0,GL_RGBA, GL_FLOAT, NULL);
>=20
> then, I get a full screen red image (even if I comment the glBegin(QUAD=
S) -
> glEnd() block to render the quad). The entire FBO gets the color of my
> glColor3ub(255,0,0).
>=20
> I have test every OpenGL code line with glGetError(), and there is not =
any
> error. I also installed latest glew and drivers for my 8800 NVidia grap=
hics
> board.
>=20
> I hope some of you could have a suggestion about what I am doing wrong.
>=20
> Thanks a lot!
> Rhadam=E9s
>=20
>=20
> #include "glew.h"
> #include <gl/glut.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <iostream>
>=20
> #define GL_TEXTURE_RECTANGLE GL_TEXTURE_RECTANGLE_NV
>=20
> int height=3D0, width=3D0;
> GLuint g_fb=3D0;
> GLuint g_tex=3D0;
> GLuint g_depth=3D0;
>=20
> using namespace std;
>=20
>=20
> void Abort(char *msg)
> {
> =A0 printf(msg);
> =A0 exit(1);
> }
>=20
>=20
>=20
> void CheckErrorsGL(const char* location=3DNULL, ostream& ostr=3D std::c=
err )
> {
> =A0 GLuint errnum;
> =A0 const char *errstr;
> =A0 int counter =3D 0;
> =A0 while (errnum =3D glGetError())
> =A0 {
> =A0=A0=A0 errstr =3D reinterpret_cast<const char *>(gluErrorString(errn=
um));
> =A0=A0=A0 if(errstr)
> =A0=A0=A0 {
> =A0=A0=A0=A0=A0 ostr << errstr;
> =A0=A0=A0 }
> =A0=A0=A0 else
> =A0=A0=A0 {
> =A0=A0=A0=A0=A0 ostr << "Error " << errnum;
> =A0=A0=A0 }
> =A0=A0 =A0
> =A0=A0=A0 if(location)
> =A0=A0=A0=A0=A0 ostr << " at " << location;=A0=A0=A0 =A0=A0=A0
> =A0=A0=A0 ostr << endl;
> =A0=A0=A0 counter++;
> =A0 }
> =A0 if (counter)
> =A0=A0=A0 Abort("Application cannot continue!\n");
>=20
> =A0 return;
> }
>=20
> void TestOpenGLError()
> {
> =A0 CheckErrorsGL(NULL);
> }
>=20
>=20
> void Draw()
> {
> =A0 // working with main object (the application)
> =A0 if (!width || !height)
> =A0=A0=A0 return;
>=20
> =A0 glClearColor(0,0,0,0);
> =A0 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
>=20
>=20
> =A0 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, g_fb);=A0 TestOpenGLError(=
);
> =A0 glDrawBuffer( GL_COLOR_ATTACHMENT0_EXT );=A0 TestOpenGLError();
> =A0 glViewport(0,0,width, height);=A0 TestOpenGLError();
> =A0 glClearColor(0,0,0,0);=A0=A0 TestOpenGLError();
> =A0 glClear(GL_COLOR_BUFFER_BIT);=A0 TestOpenGLError();
>=20
>=20
> =A0 float size =3D 100.0f;
>=20
> =A0 glColor3f(1,0,0.5f);
> =A0 glBegin(GL_QUADS);
> =A0=A0=A0 glVertex2f(width*0.5f - size, height*0.5f - size);
> =A0=A0=A0 glVertex2f(width*0.5f - size, height*0.5f + size);
> =A0=A0=A0 glVertex2f(width*0.5f + size, height*0.5f + size);
> =A0=A0=A0 glVertex2f(width*0.5f + size, height*0.5f - size);
> =A0 glEnd();
> =A0 //glColor3ub(0,0,0);
>=20
>=20
>=20
> =A0
> =A0 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
> =A0 glDrawBuffer( GL_BACK );
> =A0 glViewport(0,0,width, height);=A0 TestOpenGLError();
> =A0 glFinish();
> =A0 glEnable(GL_TEXTURE_RECTANGLE);
> =A0 glBindTexture(GL_TEXTURE_RECTANGLE, g_tex);=A0 TestOpenGLError();
> =A0 glEnable(GL_TEXTURE_RECTANGLE);=A0 TestOpenGLError();
> =A0=A0=A0
>=20
> =A0 glBegin(GL_QUADS);
> =A0=A0=A0 glTexCoord2f(0.0f, 0.0f);
> =A0=A0=A0 glVertex2f(0.0f, 0.0f);
> =A0=A0=A0 glTexCoord2f(0.0f, height);
> =A0=A0=A0 glVertex2f(0.0f, height);
> =A0=A0=A0 glTexCoord2f(width, height);
> =A0=A0=A0 glVertex2f(width, height);
> =A0=A0=A0 glTexCoord2f(width, 0.0f);
> =A0=A0=A0 glVertex2f(width, 0.0f);
> =A0 glEnd();
>=20
> =A0 glDisable(GL_TEXTURE_RECTANGLE);=A0 TestOpenGLError();
> =A0 // back to 3D mode
>=20
>=20
> =A0 glFinish();
> =A0 glutSwapBuffers();
> }
>=20
> void Init()
> {
> =A0 GLenum err =3D glewInit();
> =A0 if (GLEW_OK !=3D err)
> =A0=A0=A0 // Problem: glewInit failed, something is seriously wrong.
> =A0=A0=A0 Abort("init error\n");
>=20
>=20
> =A0 TestOpenGLError();
> =A0 glGenFramebuffersEXT(1, &g_fb);=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ;=A0=
=A0 TestOpenGLError();
> =A0 glBindTexture(GL_TEXTURE_2D, 0);=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
TestOpenGLError();
> =A0 glBindTexture(GL_TEXTURE_RECTANGLE, 0);=A0=A0=A0=A0=A0 TestOpenGLEr=
ror();
> =A0 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, g_fb); TestOpenGLError();
>=20
> =A0 // create the texture for the color
> =A0 glGenTextures(1, &g_tex);=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0&nbs p;=A0=A0=
=A0=A0=A0=A0=A0=A0 TestOpenGLError();
> =A0 glBindTexture(GL_TEXTURE_RECTANGLE, g_tex);=A0 TestOpenGLError();
>=20
> =A0 glTexParameteri (GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP)=
;
> =A0 glTexParameteri (GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP)=
;
> =A0 glTexParameteri (GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_NE=
AREST);
> =A0 glTexParameteri (GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_NE=
AREST); TestOpenGLError();=A0=A0=A0=A0=A0=A0=A0=A0=A0&nbs p;
>=20
> =A0 //glTexImage2D(GL_TEXTURE_RECTANGLE, 0, 4, width, height, 0, GL_RGB=
A, GL_UNSIGNED_BYTE, NULL);=A0=A0=A0=A0=A0=A0=A0=A0=A0 //works
> =A0 //glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA16, width, height, 0=
,GL_RGBA, GL_UNSIGNED_SHORT, NULL);=A0 //works
> =A0 //glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_FLOAT_RGBA32_NV, w, h, 0=
,GL_RGBA, GL_FLOAT, NULL);=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 //does not work
> =A0 glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_FLOAT_RGBA16_NV, width, he=
ight, 0,GL_RGBA, GL_UNSIGNED_SHORT, NULL);
> =A0
> =A0 TestOpenGLError();
> =A0 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_E=
XT,GL_TEX TURE_RECTANGLE,g_tex, 0);
> =A0 if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) !=3D GL_FRAMEBU=
FFER_COMPLETE_EXT)
> =A0=A0=A0 Abort("Error adding color to FBO\n");
> =A0 TestOpenGLError();
>=20
> =A0 glMatrixMode(GL_PROJECTION);
> =A0 glLoadIdentity();
> =A0 glOrtho(0,width,0,height,-1,100.0f);
> =A0 glMatrixMode(GL_TEXTURE);
> =A0 glLoadIdentity();
> =A0 glMatrixMode(GL_MODELVIEW);
> =A0 glLoadIdentity();
> =A0 glTranslatef(0,0,-5);
> }
>=20
> void Reshape(int w, int h)
> {
> =A0 width =3D w;
> =A0 height=3D h;
> =A0 glViewport(0,0,width,height);
> =A0 Init();
> }
>=20
>=20
> void main(int argc, char **argv)
> {
> =A0 glutInit(&argc, argv);
> =A0 glutInitDisplayString("double blue>=3D8 red>=3D8 alpha>=3D8 green>=3D=
8 depth=3D32");// rgba>=3D8 depth>=3D24");
> =A0 glutInitWindowSize(640,480);
> =A0 glutInitWindowPosition(0,0);
> =A0 glutCreateWindow("test");
> =A0 glutSetWindowTitle("test");
>=20
>=20
> =A0 glutIdleFunc(Draw);
> =A0 glutDisplayFunc(Draw);
> =A0 glutReshapeFunc(Reshape);
>=20
> =A0 glutShowWindow();
> =A0 glutMainLoop();
>=20
> }
> =A0 ----- FAQ and OpenGL Resources at: http://www.geocities.com/Silicon=
Valley/Hills/9956/OpenGL -- Author: [email protected]
> INET: [email protected] Fat City Hosting, San Diego, California -- http:=
//www.fatcity.com
> --------------------------------------------------------------------- T=
o REMOVE yourself from this mailing list, send an
> E-Mail message to: [email protected] (note EXACT spelling of 'ListGu=
ru') and in the message BODY, include a line
> containing: UNSUB OPENGL-GAMEDEV-L (or the name of mailing list you wan=
t to be removed from). You may also send the HELP
> command for other information (like subscribing).
>
Servus,
Gernot
GPU. 3D Vision. Europe. Future. Now.
Drop by: www.mpi-sb.mpg.de/~gziegler - www.geofront.eu
---430484219-2061248159-1217409512=:15420--
-----
FAQ and OpenGL Resources at:
http://www.geocities.com/SiliconValley/Hills/9956/OpenGL
--
Author: Gernot Ziegler
INET: [email protected]
Fat City Hosting, San Diego, California -- http://www.fatcity.com
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: [email protected] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB OPENGL-GAMEDEV-L
(or the name of mailing list you want to be removed from). You may
also send the HELP command for other information (like subscribing).