problem with code

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(&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 ^^

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

Try passing GL_LINES (with an extra S) as the argument to glBegin

none of both worked :frowning:

And what dmesg says ?

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

god, you are right i forgot the glFlush().
why the lack of this function caused all this?

??? badly written drivers ???
Seem you are not alone seeing this error code :
http://forums.opensuse.org/english/get-h…-more-info.html

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.

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 ^^