Originally posted by davepermen:
any pics how the mipmap-levels look like?
Davepermen, I have some problems to post the image in a webpage, but
I’m sending now a complete glut code where the problem is presented.
It’s small and simple.
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
#include"GL/gl.h"
#include"glut.h"
void InitOpenGL()
{
//glEnable(GL_DEPTH_TEST);
//glEnable(GL_CULL_FACE);
//glDepthFunc(GL_LESS);
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glPixelStorei(GL_PACK_ALIGNMENT,1);
}
void DrawTexture(float width,float height)
{
glEnable(GL_TEXTURE_2D);
glBegin(GL_POLYGON);
glTexCoord2d(0.0,0.0);
glVertex2f(0,0);
glTexCoord2d(1.0,0.0);
glVertex2f(width,0);
glTexCoord2d(1.0,1.0);
glVertex2f(width,height);
glTexCoord2d(0.0,1.0);
glVertex2f(0,height);
glEnd();
glDisable(GL_TEXTURE_2D);
}
void BuildMipmap()
{
int i;
GLuint handle;
glGenTextures(1,&(handle));
glBindTexture(GL_TEXTURE_2D,handle);
// glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
// glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE, GL_REPLACE);
glReadBuffer(GL_BACK);
//glDisable(GL_DEPTH_TEST);
glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,0,0,256,256,0);
glCopyTexImage2D(GL_TEXTURE_2D,1,GL_RGBA8,0,0,128,128,0);
glCopyTexImage2D(GL_TEXTURE_2D,2,GL_RGBA8,0,0,64,64,0);
glCopyTexImage2D(GL_TEXTURE_2D,3,GL_RGBA8,0,0,32,32,0);
glCopyTexImage2D(GL_TEXTURE_2D,4,GL_RGBA8,0,0,16,16,0);
glCopyTexImage2D(GL_TEXTURE_2D,5,GL_RGBA8,0,0,8,8,0);
glCopyTexImage2D(GL_TEXTURE_2D,6,GL_RGBA8,0,0,4,4,0);
glCopyTexImage2D(GL_TEXTURE_2D,7,GL_RGBA8,0,0,2,2,0);
glCopyTexImage2D(GL_TEXTURE_2D,8,GL_RGBA8,0,0,1,1,0);
for (i=0;i<=6;i++)
{
//glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_BASE_LEVEL, i);
//glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAX_LEVEL, i);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
DrawTexture((float)(256/(1<<i)),(float)(256/(1<<i)));
glutSwapBuffers();
printf("level:%d
",i);
getch();
}
//glEnable(GL_DEPTH_TEST);
}
void DrawScene()
{
glClearColor(0.0,0.0,0.0,1.0);
glColor3ub(255,255,255);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glBegin(GL_POLYGON);
glVertex2f(0,0);
glVertex2f(256,0);
glVertex2f(256,256);
glVertex2f(0,0);
glEnd();
}
void Display(void)
{
DrawScene();
BuildMipmap();
glFlush();
glutSwapBuffers();
}
void MyReshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, (GLdouble) w, 0.0, (GLdouble) h);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void main(int argc, char ** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(256,256);
glutCreateWindow(“Teste”);
glutReshapeFunc(MyReshape);
glutDisplayFunc(Display);
InitOpenGL();
glutMainLoop();
}
I’ve shown this to several people that work with opengl and nobody could
find the error source. We think there’s some problem with the acceleration
mechanism in the geforce boards(we experimented with geforce 2 and 3), but
I hope it’s not. I don’t know why its mixing up the data stored in level 0 of the
mipmap. If I change to GL_RGBA4 the problem changes to other levels.
I know that there’s now more efficiente ways to do a fast mipmap construction by
rendering to texture, pbuffers and SGIS extension but I’m very curious about what’s happening.
Could you please take a look at this?
Thank you very much.