LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-05-2007, 04:16 PM   #1
nacio
LQ Newbie
 
Registered: Mar 2007
Location: Italy
Distribution: Debian
Posts: 18

Rep: Reputation: 0
gl program showing nothing on screen


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();
}

Last edited by nacio; 04-05-2007 at 04:18 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
clone mode ~ showing only one screen jasondodd Linux - Hardware 0 01-26-2007 07:58 AM
Program icons not showing up on taskbar royeo Linux - General 1 08-01-2006 04:49 PM
In login screen,error in showing dhanju Linux - Software 1 05-22-2006 07:57 AM
why does my computer shutdown instead of showing a login screen??? staticborris SUSE / openSUSE 2 12-09-2005 04:32 PM
TOP, showing a program i don't believe i started JerryMcFarts Linux - Security 4 04-20-2005 01:37 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration