Alex Romosan wrote:
> still trying to figure out the real reason why the nvidia driver is
> slow when we enable GL_POINT_SMOOTH in fgfs (and learning a lot more
> about openGL then i ever wanted to know). 

I've modified your test program to follow what is done in flightgear,
and looks like the problem is the lack of acceleration when drawing
triangles in point mode. So, if this is right, we can't get the
acceleration again without changing the way lights are drawn.

The test program now draws the same data as triangles or just points
primitives (toggle with the p key). And you can toggle the
GL_POINT_SMOOTH with the s key. The r key stop the rotation to better
view the result. And the m key change the polygon mode (fill, line or
point). The frame-rate is printed to stdout every second.

Diogo.
#include <stdio.h>
#include <stdlib.h>

#include <GL/gl.h>      /* Header File For The OpenGL Library */
#include <GL/glu.h>     /* Header File For The GLU Library */
#include <GL/glut.h>

#define NB_PIXELS 10000


GLfloat pixels[NB_PIXELS*3];
int drawprim = GL_POINTS, drawmode = GL_POINT;
float rot = 2.0;
struct timeval last_ts, now_ts;

void GLUTdraw(void)
{
  static int count = 0;
  int i;
	
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

  //glRotatef(2.0,1.0,1.0,1.0);
  glRotatef(rot,0.0,0.0,1.0);

  glColor4ub(255,255,255,255);
  glBegin(drawprim);
  for(i=0;i<NB_PIXELS/3;i++)
  {
    glVertex3f(pixels[3*3*i],pixels[3*3*i+1],pixels[3*3*i+2]);
    glVertex3f(pixels[3*3*i+3],pixels[3*3*i+4],pixels[3*3*i+5]);
    glVertex3f(pixels[3*3*i+6],pixels[3*3*i+7],pixels[3*3*i+8]);
  }
  glEnd();
  glutSwapBuffers();
  
  /* print framerate every second */
  count++;
  gettimeofday(&now_ts, NULL);
  //printf("time=%d\n", now_ts.tv_sec);
  if (last_ts.tv_sec != now_ts.tv_sec)
  {
    last_ts.tv_sec = now_ts.tv_sec;
    printf ("FPS=%d\n", count);
    count = 0;
  }
}

static void Key (unsigned char key, int x, int y)
{
  static char s = 1;

  (void) x;
  (void) y;
  switch (key)
  {
    case 27:
      exit (0);
      break;
    case 's':
	s = !s;
	if (s)
	  glEnable(GL_POINT_SMOOTH);
	else
	  glDisable(GL_POINT_SMOOTH);
	break;
    case 'r':
	if (rot)
	  rot = 0.0;
	else
	  rot = 2.0;
	break;
    case 'p':
	if (drawprim == GL_POINTS)
	  drawprim = GL_TRIANGLES;
	else
	  drawprim = GL_POINTS;
	break;
    case 'm':
	if (drawmode == GL_FILL)
	  drawmode = GL_POINT;
	else if (drawmode == GL_POINT)
	  drawmode = GL_LINE;
	else
	  drawmode = GL_FILL;
	glPolygonMode(GL_FRONT, drawmode);
	break;
  }
}

int main(int argc,char *argv[])
{
  int i;
	
  for(i=0;i<NB_PIXELS/3;i++)
  {
    pixels[3*3*i]=rand()%250-125;
    pixels[3*3*i+1]=rand()%250-125;
    pixels[3*3*i+2]=rand()%250-125;
    pixels[3*3*i+3]=pixels[3*3*i]+5;
    pixels[3*3*i+4]=pixels[3*3*i+1];
    pixels[3*3*i+5]=pixels[3*3*i+2];
    pixels[3*3*i+6]=pixels[3*3*i];
    pixels[3*3*i+7]=pixels[3*3*i+1]+5;
    pixels[3*3*i+8]=pixels[3*3*i+2];
  }
  
  
  glutInit(&argc, argv);		// initialize the toolkit
  glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL);
  glutInitWindowSize(800,600);	// set window size
  glutInitWindowPosition(100, 150);	// set window position on screen
  glutCreateWindow("testgl"); // open the screen window

  glutDisplayFunc(GLUTdraw);
  glutKeyboardFunc (Key);
  glutIdleFunc(GLUTdraw);

  glViewport(0,0,800,600);

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  //glOrtho(-100,100,-100,100,-500,500);
  gluPerspective(60, 1, -500, 500);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  glTranslatef(0.0, 0.0, -500);

  glPolygonMode(GL_FRONT, drawmode);
  glEnable(GL_POINT_SMOOTH);
  glHint(GL_POINT_SMOOTH_HINT,GL_DONT_CARE);
  glEnable(GL_LINE_SMOOTH);
  glHint(GL_LINE_SMOOTH_HINT,GL_DONT_CARE);
  glPointSize(5.0f);
  glEnable(GL_BLEND);
  glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ;
  
  gettimeofday(&last_ts, NULL);
  glutMainLoop();

  return 0;
}

Reply via email to