PDA

View Full Version : Can't enable GL_POLYGON_SMOOTH. Can you HELP?



Sergei
10-12-2000, 06:16 AM
I have RIVA TNT2. I can enable smooth for point and lines, but for fill polygons it not work. Is it a problem with VideoCard, drivers or my head???

mcraighead
10-12-2000, 09:22 PM
Try setting the polygon smooth hint to GL_NICEST.

This is intentional on our part to make it clear that you may not really want polygon smoothing, given the massive performance hit it entails.

Our Quadro products support polygon smoothing in hardware. The GL_NICEST restriction is lifted there.

- Matt

Sergei
10-12-2000, 09:46 PM
What is GL_NICEST???
I can't find in help. Can you post small sample?

mcraighead
10-12-2000, 09:56 PM
Try adding this line of code at initialization time:

glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);

Make sure you're also setting up some alpha blending, or you won't see any obvious effect. This is described in the redbook in further detail.

- Matt

Sergei
10-15-2000, 05:20 AM
I added. Not change. Smooth for filled polygon is off. When i start my program on computer with out hardware support openGl, everything work perfect, but slowly.

mcraighead
10-15-2000, 12:23 PM
That should have worked. Can you send me your app so I can try it on my system and debug it? See my info for my email address.

- Matt

Sergei
10-16-2000, 01:36 AM
I use cross-platform library QT. And you will have problem with compile my sources.

#include <main.h>
#include <windows.h>

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glaux.h>

#include <qfile.h>
#include <qstring.h>

int Lists[65536]; // list's number
int Listscount=0;

int Load_GL_objects (QString & filename1,QString &filename2)
{
QFile f(filename1);
QFile o(filename2);

QString s;

float (*vertex)[2]; // array of points
int (*triangl)[3]; // array of index for triangles;
int *object; // array start pointov triangles;
int vertexcount=0;
int trianglcount=0;
int objectcount=0;

int r,i,j,k;
const char *str;
char temp = 0;


f.open(IO_ReadOnly);
for (r=0;r<14;r++)
f.readLine(s,1000); // read cooment from files.

f.readLine(s,1000); // read count vertex
s.remove(0,3);
r=0;
while (s[r]!=' ') r++;
s.remove(r,s.length()-r);
r=s.toInt();
vertexcount = r;

f.readLine(s,1000); // read count triang
s.remove(0,3);
r=0;
while (s[r]!=' ') r++;
s.remove(r,s.length()-r);
r=s.toInt();

trianglcount = r;

// go to vertex array
f.readLine(s,1000);
s.remove(10,s.length()-10);

while (s!="static GLf")
{
f.readLine(s,1000);
s.remove(10,s.length()-10);
str=s.ascii();
if (s=="// Object:") objectcount++;
}
// read vertex array
vertex = new float[vertexcount][2];
triangl = new int[trianglcount][3];
object = new int[objectcount];

for (r=0;r<vertexcount;r++)
{
while (temp!='{') f.readBlock(&temp,1);
j=0;
s="";
while (temp!='f')
{
f.readBlock(&temp,1);
s.insert(j++,temp);
}
vertex[r][0]=s.toFloat();
f.readBlock(&temp,1);
j=0;
s="";
while (temp!='f')
{
f.readBlock(&temp,1);
s.insert(j++,temp);
}
vertex[r][1]=s.toFloat();
f.readBlock(&temp,1);
j=0;
s="";
while (temp!='f')
{
f.readBlock(&temp,1);
s.insert(j++,temp);
}

}
f.close();
f.open(IO_ReadOnly);
f.readLine(s,1000);
s.remove(6,s.length()-6);

while (s!="static")
{
f.readLine(s,1000);
s.remove(6,s.length()-6);
str=s.ascii();
}

while (s!="// Object:")
{
f.readLine(s,1000);
s.remove(10,s.length()-10);
str=s.ascii();
}
temp=' ';
object[0]=0;
k=0;
s="";
for (r=0;r<trianglcount;r++)
{

while ((temp!='{')&&(temp!='/')) f.readBlock(&temp,1);
if (temp=='/') object[++k]=r;
j=0;
while ((temp!='{')) f.readBlock(&temp,1);
while (temp!=',')
{
f.readBlock(&temp,1);
s.insert(j++,temp);
}
s.remove(j-1,1);
str=s.ascii();
triangl[r][0]=s.toInt();
j=0;
s="";
temp =' ';
while (temp!=',')
{
f.readBlock(&temp,1);
s.insert(j++,temp);
}
s.remove(j-1,1);
str=s.ascii();
triangl[r][1]=s.toInt();
j=0;
s="";
temp ='z';
while (temp!=' ')
{
f.readBlock(&temp,1);
s.insert(j++,temp);
}
s.remove(j-1,1);
str=s.ascii();
triangl[r][2]=s.toInt();
temp=' ';
s="";


}
f.close();

o.open(IO_WriteOnly);
o.writeBlock((char *)&vertexcount, sizeof (int));
o.writeBlock((char *)&trianglcount, sizeof (int));
o.writeBlock((char *)&objectcount, sizeof (int));

o.writeBlock((char *)vertex, (sizeof (float))*vertexcount*2);
o.writeBlock((char *)triangl, (sizeof (int))*trianglcount*3);
o.writeBlock((char *)object, (sizeof (int))*objectcount*2);

o.close();

// Read objects from file.

o.open(IO_ReadOnly);
o.readBlock((char *)&vertexcount, sizeof (int));
o.readBlock((char *)&trianglcount, sizeof (int));
o.readBlock((char *)&objectcount, sizeof (int));

o.readBlock((char *)vertex, (sizeof (float))*vertexcount*2);
o.readBlock((char *)triangl, (sizeof (int))*trianglcount*3);
o.readBlock((char *)object, (sizeof (int))*objectcount*2);

o.close();
int h=0;
for (i=0;i<objectcount-1;i++)
{
Lists[Listscount++]=glGenLists(1);h++;
glNewList(Lists[Listscount-1], GL_COMPILE);
glBegin (GL_TRIANGLES);
for(j=object[i];j<object[i+1];j++)
for(k=0;k<3;k++)
{
int vi=triangl[j][k];
glVertex2f (vertex[vi][0],vertex[vi][1]);
}
glEnd ();
glEndList();
}

Lists[Listscount++]=glGenLists(1);
glNewList(Lists[Listscount-1], GL_COMPILE);h++;
glBegin (GL_TRIANGLES);

for(j=object[objectcount-1];j<trianglcount;j++)
for(k=0;k<3;k++)
{
int vi=triangl[j][k];
glVertex2f (vertex[vi][0],vertex[vi][1]);
}
glEnd ();
glEndList();

delete []triangl;
delete []vertex;
delete []object;
return h;


}

void CALLBACK resize(int width,int height)
{
if (width<=height) height=width;
else width=height;
glViewport(0,0,width,height);
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho(-5,5, -5,5, 2,12);
gluLookAt( 0,0,5, 0,0,0, 0,1,0 );
glMatrixMode( GL_MODELVIEW );
}


void CALLBACK display(void)
{

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

int s,f;
QString sr;
s=GetTickCount();
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
glEnable(GL_POLYGON_SMOOTH);
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
glColor3f(1,1,1);
glCallLists(1,GL_INT,&(Lists[0]));


glColor3f(0.7,0.7,0.7);
glCallLists(24,GL_INT,&(Lists[1]));

glColor3f(0,0,0);
glCallLists(32,GL_INT,&(Lists[25]));

glColor3f(0,0,0);
glCallLists(47,GL_INT,&(Lists[57]));


glDisable(GL_POLYGON_SMOOTH);
auxSwapBuffers();
f=GetTickCount();
sr.setNum(f-s);
::MessageBox(0,"Time",sr.ascii(),MB_OK);


}

int main( int argc, char **argv )
{

// init OpenGL
auxInitPosition(1, 1, 300, 300);
auxInitDisplayMode( AUX_RGB | AUX_DEPTH | AUX_DOUBLE );
auxInitWindow( "OpenGL Window" );
glEnable(GL_ALPHA_TEST);
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_BLEND);
glEnable(GL_FOG);


glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ;

Load_GL_objects(QString("cell_rect.txt"),QString("cell_rect1.txt"));
Load_GL_objects(QString("cell_fills.txt"),QString("cell_fills1.txt"));
Load_GL_objects(QString("cell_outlines.txt"),QString("cell_outlines1.txt"));
Load_GL_objects(QString("cell_names.txt"),QString("cell_names1.txt"));

auxReshapeFunc(resize);
auxMainLoop(display);
auxQuit();

glDeleteLists(Lists[0],Listscount);


return 0;
}

Sergei
10-16-2000, 06:58 AM
I did it!!!! I draw may object by filled polygons, and then draw it again how smooth lines. Is it correct way?

mcraighead
10-16-2000, 09:25 AM
Originally posted by Sergei:
I did it!!!! I draw may object by filled polygons, and then draw it again how smooth lines. Is it correct way?

That shouldn't be necessary. Is there any way you can send me a Windows binary so I can run the app and debug it? I don't have the QT library.

- Matt