|
刚学VR 和 OSG。
我本想用OpenGL 做一个像画图板一样可以用鼠标画图的程序, 但是总是出问题。
想问问用OSG也可以吗?
可以的话高手,指点指点,我可以少通宵几次。
跪求!!!
我用OpenGL做的程序,总是出现问题,画一回儿,刚画的就自动没了。
希望高手指点 !!
//===============================================================
#include <GL/glut.h>
GLsizei winWidth = 400, winHeight = 300;
void init (void)
{
glClearColor (0.0, 0.0, 1.0, 1.0);
glMatrixMode (GL_PROJECTION);
gluOrtho2D (0.0, 200.0, 0.0, 150.0);
}
void displayFcn (void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 0.0, 0.0);
glPointSize (3.0);
}
void winReshapeFcn (GLint newWidth, GLint newHeight)
{
glViewport (0, 0, newWidth, newHeight);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D (0.0, GLdouble (newWidth), 0.0, GLdouble (newHeight));
winWidth = newWidth;
winHeight = newHeight;
}
void plotPoint (GLint x, GLint y)
{
glBegin (GL_POINTS);
glVertex2i (x, y);
glEnd ();
/*
glBegin(GL_LINES);
glVertex2i (x, y);
glVertex2i (0, 0);
glEnd();
*/
}
void curveDrawing (GLubyte curvePlotKey, GLint xMouse, GLint yMouse)
{
GLint x = xMouse;
GLint y = winHeight - yMouse;
switch (curvePlotKey)
{
case 'a':
plotPoint (x, y);
break;
default:
break;
}
glFlush ();
}
void main (int argc, char** argv)
{
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition (100, 100);
glutInitWindowSize (winWidth, winHeight);
glutCreateWindow ("Keyboard Curve - Drawing");
init ();
glutDisplayFunc (displayFcn);
glutReshapeFunc (winReshapeFcn);
glutKeyboardFunc (curveDrawing);
glutMainLoop ();
}
//=============================================================== |
|