Hi,
I've made a small program to test the speed of OpenGL 2D graphics. I'm working under linux/X11. My program works... when dri is not enabled. When it is, the program runs naturally faster, but it displays nothing on screen! I'm confused, is it that I forgot to call some initialization routine? Then why does it work when dri is disabled?
Here's the code:
Code:
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <GL/gl.h>
#include <GL/glut.h>
int glutWin;
void videoInit(int argc, char *argv[]) {
glutInitWindowSize(800, 600);
glutInitWindowPosition(1, 1);
glutInit( &argc, argv);
glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH );
glutWin = glutCreateWindow("GL 2D speed test");
glShadeModel(GL_FLAT);
glClearColor(0.00, 0.00, 0.00, 0.00);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glViewport(0, 0, 800, 600);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glOrtho(0.00, 1.00, 0.00, 1.00, 0.00, 1.00 );
}
void videoClose(void)
{
glutDestroyWindow(glutWin);
}
//fill in the buffer with random colors
void randomize(char *p, int qty) {
int i;
for (i=0; i<qty; i++)
*p++ = rand() & 0xFF;
}
int main(int argc, char *argv[]) {
clock_t t;
int i;
void *p;
videoInit(argc, argv);
p = malloc(800*600*4);
if (!p) {
fprintf(stderr, "can't get enough memory!\n");
return 1;
}
randomize(p, 800*600*4);
t = clock();
for (i=0; i<1000; i++) {
//this line is to see something moving on screen
//so that we see that the buffer is actually being redrawn
*(int *) (p+i) = 0;
//and now we actually draw
glDrawPixels(800, 600, GL_RGBA, GL_UNSIGNED_BYTE, p);
glFlush();
}
printf("Time: %i\n", clock() - t );
videoClose();
}