最終更新: mikk_ni3_92 2008年07月22日(火) 14:53:06履歴
現在地 >> メニュー >> サンプルコード::OpenGL >> ドラッグ処理 >>ドラッグ処理2
#include <GL/glut.h>
void display();
void reshape(int w, int h);
void myMouseFunc(int button, int state,int x, int y);
void myMouseMotion(int x,int y);
/**********[OpenGLの初期設定]**********************/
inline void GLUT_INIT()
{
glutInitDisplayMode(GLUT_RGBA);
}
inline void GLUT_CALL_FUNC()
{
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMouseFunc(myMouseFunc);
glutMotionFunc(myMouseMotion);
}
inline void MY_INIT()
{
glClearColor(1.0, 1.0, 1.0, 1.0);
glutSetCursor(GLUT_CURSOR_CROSSHAIR);
}
int main(int argc, char *argv[])
{
glutInit(&argc,argv);
GLUT_INIT();
glutCreateWindow("window name");
GLUT_CALL_FUNC();
MY_INIT();
glutMainLoop();
return 0;
}
/********[ここから、各種コールバック]****************************************/
void display(void)
{
glFlush();
}
void reshape(int w, int h)
{
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, w, h, 0 ,-1,1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
bool mouseFlag = GL_FALSE;
void myMouseFunc(int button, int state,int x, int y)
{
if( button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
mouseFlag = GL_TRUE;
glColor3d(1.0, 0.0, 0.0);
glPointSize(1);
glBegin(GL_POINTS);
glVertex2d(x,y);
glEnd();
glutPostRedisplay();
}
else
{
mouseFlag = GL_FALSE;
}
}
void myMouseMotion(int x,int y)
{
if(mouseFlag == GL_FALSE)return;
glColor3d(1.0, 0.0, 0.0);
glPointSize(1);
glBegin(GL_POINTS);
glVertex2d(x,y);
glEnd();
glutPostRedisplay();
}
#include <GL/glut.h>
void display();
void reshape(int w, int h);
void myMouseFunc(int button, int state,int x, int y);
void myMouseMotion(int x,int y);
/**********[OpenGLの初期設定]**********************/
inline void GLUT_INIT()
{
glutInitDisplayMode(GLUT_RGBA);
}
inline void GLUT_CALL_FUNC()
{
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMouseFunc(myMouseFunc);
glutMotionFunc(myMouseMotion);
}
inline void MY_INIT()
{
glClearColor(1.0, 1.0, 1.0, 1.0);
glutSetCursor(GLUT_CURSOR_CROSSHAIR);
}
int main(int argc, char *argv[])
{
glutInit(&argc,argv);
GLUT_INIT();
glutCreateWindow("window name");
GLUT_CALL_FUNC();
MY_INIT();
glutMainLoop();
return 0;
}
/********[ここから、各種コールバック]****************************************/
void display(void)
{
glFlush();
}
void reshape(int w, int h)
{
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, w, h, 0 ,-1,1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
bool mouseFlag = GL_FALSE;
void myMouseFunc(int button, int state,int x, int y)
{
if( button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
mouseFlag = GL_TRUE;
glColor3d(1.0, 0.0, 0.0);
glPointSize(1);
glBegin(GL_POINTS);
glVertex2d(x,y);
glEnd();
glutPostRedisplay();
}
else
{
mouseFlag = GL_FALSE;
}
}
void myMouseMotion(int x,int y)
{
if(mouseFlag == GL_FALSE)return;
glColor3d(1.0, 0.0, 0.0);
glPointSize(1);
glBegin(GL_POINTS);
glVertex2d(x,y);
glEnd();
glutPostRedisplay();
}