[ create a new paste ] login | about

Link: http://codepad.org/uTZTuch0    [ raw code | output | fork ]

C++, pasted on Jun 9:
#include <stdio.h>
#include "glut.h"
#include "gl.h"
#include "glu.h"
#include <math.h>

 void display();
 void reshape(int w, int h);
 void timer(int value);
 void mouse(int button, int state,int x, int y);
 
void DRAW_XYZ();
 
//using namespace std;
 

//inline void GLUT_INIT()

void Init()
 {
 glutInitDisplayMode(GLUT_RGBA| GLUT_DOUBLE | GLUT_DEPTH);
 glutInitWindowSize(200,200);
 }
 
//inline void GLUT_CALL_FUNC()
void GLUT_CALL_FUNC() 
 {
 glutDisplayFunc(display);
 glutReshapeFunc(reshape);
 glutTimerFunc(10,timer,0);
 glutMouseFunc(mouse);
 }
 
//inline void MY_INIT 
void myInit()
 {
 glClearColor(1.0, 1.0, 1.0, 1.0);
 glEnable(GL_LIGHTING);
 glEnable(GL_LIGHT0);
 }
 

int main(int argc, char **argv)
 {
 glutInit(&argc,argv);
 Init();
 glutCreateWindow("name");
 GLUT_CALL_FUNC();
 myInit();
 glutMainLoop();
 
return 0;
 }
 
GLfloat light_pos[] = { 0.0, 3.0, 5.0, 1.0 };
 GLfloat red[] = { 0.8, 0.2, 0.2, 1.0 };
 GLfloat blue[] = { 0.2, 0.2, 0.8, 1.0 };
 /********[ここからコールバック]****************************************/
 void display()
 {
 
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
glLoadIdentity();
 gluLookAt(3, 4, 5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
 
glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
 

glEnable(GL_DEPTH_TEST);
 

glPushMatrix();
 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, red);
 

glBegin(GL_QUADS);
 glNormal3d(0,1,1);
 glVertex3f(0,0,0);
 glVertex3f(2,0,0);
 glVertex3f(2,2,0);
 glVertex3f(0,2,0);
 glEnd();
 glPopMatrix();
 

glPushMatrix();
 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, red);
 glBegin(GL_QUADS);
 glNormal3d(1,1,0);
 glVertex3f(0,0,0);
 glVertex3f(0,0,2);
 glVertex3f(0,2,2);
 glVertex3f(0,2,0);
 glEnd();
 glPopMatrix();
 

glPushMatrix();
 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, blue);
 DRAW_XYZ();
 glPopMatrix();
 
glDisable(GL_DEPTH_TEST);
 

glutSwapBuffers();
 
}
 

int window_h;
 void reshape(int w, int h)
 {
 window_h = h;
 glViewport(0, 0, w, h);
 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 gluPerspective(30.0, (double)w / (double)h, 1.0, 100.0);
 glMatrixMode(GL_MODELVIEW);
 
}
 
void timer(int value)
 {
 glutPostRedisplay();
 glutTimerFunc(1,timer,0); //タイマー関数
 }
 

void DRAW_XYZ()
 {
 glBegin(GL_LINES);
 

glVertex2d(-100,0);
glVertex2d(100, 0);
 
glVertex2d(0,0);
 glVertex2d(0,100);
 

glVertex3d(0,0,-100);
 glVertex3d(0,0, 100);
 
glEnd();
 
}
 

void mouse(int button, int state, int x, int y)
 {
 if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
 GLdouble model[16], proj[16];
 GLint view[4];
 GLfloat z;
 GLdouble ox, oy, oz;
 
/*** 各種行列の取得 ***/
 glGetDoublev(GL_MODELVIEW_MATRIX, model);
 glGetDoublev(GL_PROJECTION_MATRIX, proj);
 glGetIntegerv(GL_VIEWPORT, view);
 

/*****クリック位置(ピクセル)の奥行き値を取得*********/
 glReadPixels(x, window_h - y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z);
 
/* ox, oy, oz にクリックしたところの3次元位置が入る */
 gluUnProject(x, window_h - y, z, model, proj, view, &ox, &oy, &oz);
 
/**テスト用出力***/
 printf("(x,y,z)=(%f,%f,%f)\n",ox,oy,oz);
 

}
 }


Output:
1
2
3
4
5
6
Line 17: error: glut.h: No such file or directory
Line 15: error: gl.h: No such file or directory
Line 16: error: glu.h: No such file or directory
In function 'void Init()':
Line 21: error: 'GLUT_RGBA' was not declared in this scope
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: