PDA

View Full Version : problem with code



NetRaider
10-08-2010, 02:12 AM
hi, i'm at the beggining of opengl, trying to test some functions i can't do this code to run correctly



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

void reshape(int w, int h);
void display(void);

int main(int argc, char **argv)
{
glutInit(&amp;argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(640, 480);
glutCreateWindow("test");
glClearColor(0.0, 0.0, 0.0, 0.0);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}

void reshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); //da modificare
gluOrtho2D(-1.0, 1.0, 1.0, -1.0);
}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_LINE);
glColor3ub(0, 255, 0);
glVertex3f(-1.0, 0.0, 0.0);
glVertex3f(1.0, 0.0, 0.0);
glColor3ub(255, 0, 0);
glVertex3f(0.0, -0.1, 0.0);
glVertex3f(0.0, 0.1, 0.0);
glEnd();
}


when i run this code i obtain a window that is not cleared, and when i try to resize it with the mouse it crashes and i obtain this error:



drmRadeonCmdBuffer: -22. Kernel failed to parse or rejected command stream. See dmesg for more info.


i code on Fedora 13 and i recently installed and then removed the proprietary drivers ati, i also tried to reinstall mesa-libGL but nothing

what is wrong whit it?

bye ^^

PascalM123
10-08-2010, 02:28 AM
Try to implement the reshape function like this, i.e. add glMatrixMode(GL_MODELVIEW):

glViewport (0, 0, w, h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-1.0, 1.0, 1.0, -1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

abolz
10-08-2010, 05:02 AM
Try passing GL_LINES (with an extra S) as the argument to glBegin

NetRaider
10-08-2010, 11:05 AM
none of both worked :(

ZbuffeR
10-08-2010, 11:20 AM
And what dmesg says ?

Rockie X.Lee
10-08-2010, 10:51 PM
use glFlush()

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_LINES);
glColor3ub(0, 255, 0);
glVertex3f(-1.0, 0.0, 0.0);
glVertex3f(1.0, 0.0, 0.0);
glColor3ub(255, 0, 0);
glVertex3f(0.0, -0.1, 0.0);
glVertex3f(0.0, 0.1, 0.0);
glEnd();
glFlush();
}

NetRaider
10-09-2010, 01:03 AM
god, you are right i forgot the glFlush().
why the lack of this function caused all this?

ZbuffeR
10-09-2010, 01:35 AM
??? badly written drivers ???
Seem you are not alone seeing this error code :
http://forums.opensuse.org/english/get-h...-more-info.html (http://forums.opensuse.org/english/get-help-here/applications/433294-drmradeoncmdbuffer-22-kernel-failed-parse-rejected-command-stream-see-dmesg-more-info.html)

mhagain
10-09-2010, 06:24 AM
Not many people create a single-buffered context these days I would guess. Driver support might definitely be a bit ropey. You might try changing it to double-buffered (using GLUT_DOUBLE instead of GLUT_SINGLE in your glutInitDisplayMode call) and then use glutSwapBuffers at the end of your display function. It will run faster, give you a more stable image, won't need glFlush and shouldn't crash.

NetRaider
10-09-2010, 07:16 AM
adding glFlush the program works properly.
by the way it's definitely a driver problem.
i created a single buffered context only because it's a test app.
thanks for the help ^^