Shady3D
February 21st, 2009, 11:20 PM
#include <windows.h>
#include <gl/Glu.h>
#include <gl/glut.h>
void myInit(){
glPointSize(4.0); //a dot is 4*4 pixels
glColor3f(0.0,0.0,0.0); //set the drawing color
glClearColor(1.0,1.0,1.0,0.0); //set white background
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 300.0, 0.0, 300.0);
}
void myDisplay(){
glClear(GL_COLOR_BUFFER_BIT); //clear the screen
glFlush(); //send all output to display
}
void myKeyboard(unsigned char theKey, int mouseX, int mouseY){
if(theKey == 'd'){
glBegin(GL_POINTS);
glVertex2i(mouseX,300-mouseY);
glEnd();
}
else if (theKey == 'r')
glColor3f(1,0,0);
else if (theKey == 'g')
glColor3f(0,1,0);
else if (theKey == 'b')
glColor3f(0,0,1);
else
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
void myMouse(int button, int state, int x, int y){
if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){
glBegin(GL_POINTS);
glVertex2i(x,300-y);
glEnd();
}
else if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)
myDisplay();
glFlush();
}
void myMotion(int x, int y) { }
void myPassiveMotion(int x, int y) {
glBegin(GL_POINTS);
glVertex2i(x,300-y);
glEnd();
glFlush();
}
void main(int args, char** argv) {
glutInit(&args, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); //set the display mode
glutInitWindowSize(300,300); //set the window size
glutInitWindowPosition(100, 150); //set the window position on screen
glutCreateWindow("my first attempt"); //open the screen window
// register the callback functions
glutDisplayFunc(myDisplay);
glutMouseFunc(myMouse);
glutKeyboardFunc(myKeyboard);
glutMotionFunc(myMotion);
glutPassiveMotionFunc(myPassiveMotion);
myInit(); //additional init
glutMainLoop();
}
ok so this is the code that they gave us in the section of openGL and i want to run it under Linux (it worked under windows), i searched about openGL and i downloaded some packages for openGL and also tried a code from the Internet that makes a 3d box a u can rotate using mouse and it worked smoothly, and BTW i am on ubuntu 64, so if any body can help me, and thx in advance
and here is the output from the compilation
$ g++ use_keyboard_v1.cpp -o out
use_keyboard_v1.cpp:1:21: error: windows.h: No such file or directory
use_keyboard_v1.cpp:2:20: error: gl/Glu.h: No such file or directory
use_keyboard_v1.cpp:3:21: error: gl/glut.h: No such file or directory
use_keyboard_v1.cpp: In function ‘void myInit()’:
use_keyboard_v1.cpp:7: error: ‘glPointSize’ was not declared in this scope
use_keyboard_v1.cpp:8: error: ‘glColor3f’ was not declared in this scope
use_keyboard_v1.cpp:9: error: ‘glClearColor’ was not declared in this scope
use_keyboard_v1.cpp:11: error: ‘GL_PROJECTION’ was not declared in this scope
use_keyboard_v1.cpp:11: error: ‘glMatrixMode’ was not declared in this scope
use_keyboard_v1.cpp:12: error: ‘glLoadIdentity’ was not declared in this scope
use_keyboard_v1.cpp:13: error: ‘gluOrtho2D’ was not declared in this scope
use_keyboard_v1.cpp: In function ‘void myDisplay()’:
use_keyboard_v1.cpp:19: error: ‘GL_COLOR_BUFFER_BIT’ was not declared in this scope
use_keyboard_v1.cpp:19: error: ‘glClear’ was not declared in this scope
use_keyboard_v1.cpp:21: error: ‘glFlush’ was not declared in this scope
use_keyboard_v1.cpp: In function ‘void myKeyboard(unsigned char, int, int)’:
use_keyboard_v1.cpp:29: error: ‘GL_POINTS’ was not declared in this scope
use_keyboard_v1.cpp:29: error: ‘glBegin’ was not declared in this scope
use_keyboard_v1.cpp:30: error: ‘glVertex2i’ was not declared in this scope
use_keyboard_v1.cpp:31: error: ‘glEnd’ was not declared in this scope
use_keyboard_v1.cpp:34: error: ‘glColor3f’ was not declared in this scope
use_keyboard_v1.cpp:36: error: ‘glColor3f’ was not declared in this scope
use_keyboard_v1.cpp:38: error: ‘glColor3f’ was not declared in this scope
use_keyboard_v1.cpp:41: error: ‘GL_COLOR_BUFFER_BIT’ was not declared in this scope
use_keyboard_v1.cpp:41: error: ‘glClear’ was not declared in this scope
use_keyboard_v1.cpp:42: error: ‘glFlush’ was not declared in this scope
use_keyboard_v1.cpp: In function ‘void myMouse(int, int, int, int)’:
use_keyboard_v1.cpp:47: error: ‘GLUT_LEFT_BUTTON’ was not declared in this scope
use_keyboard_v1.cpp:47: error: ‘GLUT_DOWN’ was not declared in this scope
use_keyboard_v1.cpp:49: error: ‘GL_POINTS’ was not declared in this scope
use_keyboard_v1.cpp:49: error: ‘glBegin’ was not declared in this scope
use_keyboard_v1.cpp:50: error: ‘glVertex2i’ was not declared in this scope
use_keyboard_v1.cpp:51: error: ‘glEnd’ was not declared in this scope
use_keyboard_v1.cpp:53: error: ‘GLUT_RIGHT_BUTTON’ was not declared in this scope
use_keyboard_v1.cpp:55: error: ‘glFlush’ was not declared in this scope
use_keyboard_v1.cpp: In function ‘void myPassiveMotion(int, int)’:
use_keyboard_v1.cpp:64: error: ‘GL_POINTS’ was not declared in this scope
use_keyboard_v1.cpp:64: error: ‘glBegin’ was not declared in this scope
use_keyboard_v1.cpp:65: error: ‘glVertex2i’ was not declared in this scope
use_keyboard_v1.cpp:66: error: ‘glEnd’ was not declared in this scope
use_keyboard_v1.cpp:67: error: ‘glFlush’ was not declared in this scope
use_keyboard_v1.cpp: At global scope:
use_keyboard_v1.cpp:71: error: ‘::main’ must return ‘int’
use_keyboard_v1.cpp: In function ‘int main(int, char**)’:
use_keyboard_v1.cpp:73: error: ‘glutInit’ was not declared in this scope
use_keyboard_v1.cpp:74: error: ‘GLUT_SINGLE’ was not declared in this scope
use_keyboard_v1.cpp:74: error: ‘GLUT_RGB’ was not declared in this scope
use_keyboard_v1.cpp:74: error: ‘glutInitDisplayMode’ was not declared in this scope
use_keyboard_v1.cpp:75: error: ‘glutInitWindowSize’ was not declared in this scope
use_keyboard_v1.cpp:76: error: ‘glutInitWindowPosition’ was not declared in this scope
use_keyboard_v1.cpp:77: error: ‘glutCreateWindow’ was not declared in this scope
use_keyboard_v1.cpp:80: error: ‘glutDisplayFunc’ was not declared in this scope
use_keyboard_v1.cpp:81: error: ‘glutMouseFunc’ was not declared in this scope
use_keyboard_v1.cpp:82: error: ‘glutKeyboardFunc’ was not declared in this scope
use_keyboard_v1.cpp:83: error: ‘glutMotionFunc’ was not declared in this scope
use_keyboard_v1.cpp:84: error: ‘glutPassiveMotionFunc’ was not declared in this scope
use_keyboard_v1.cpp:87: error: ‘glutMainLoop’ was not declared in this scope
#include <gl/Glu.h>
#include <gl/glut.h>
void myInit(){
glPointSize(4.0); //a dot is 4*4 pixels
glColor3f(0.0,0.0,0.0); //set the drawing color
glClearColor(1.0,1.0,1.0,0.0); //set white background
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 300.0, 0.0, 300.0);
}
void myDisplay(){
glClear(GL_COLOR_BUFFER_BIT); //clear the screen
glFlush(); //send all output to display
}
void myKeyboard(unsigned char theKey, int mouseX, int mouseY){
if(theKey == 'd'){
glBegin(GL_POINTS);
glVertex2i(mouseX,300-mouseY);
glEnd();
}
else if (theKey == 'r')
glColor3f(1,0,0);
else if (theKey == 'g')
glColor3f(0,1,0);
else if (theKey == 'b')
glColor3f(0,0,1);
else
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
void myMouse(int button, int state, int x, int y){
if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){
glBegin(GL_POINTS);
glVertex2i(x,300-y);
glEnd();
}
else if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)
myDisplay();
glFlush();
}
void myMotion(int x, int y) { }
void myPassiveMotion(int x, int y) {
glBegin(GL_POINTS);
glVertex2i(x,300-y);
glEnd();
glFlush();
}
void main(int args, char** argv) {
glutInit(&args, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); //set the display mode
glutInitWindowSize(300,300); //set the window size
glutInitWindowPosition(100, 150); //set the window position on screen
glutCreateWindow("my first attempt"); //open the screen window
// register the callback functions
glutDisplayFunc(myDisplay);
glutMouseFunc(myMouse);
glutKeyboardFunc(myKeyboard);
glutMotionFunc(myMotion);
glutPassiveMotionFunc(myPassiveMotion);
myInit(); //additional init
glutMainLoop();
}
ok so this is the code that they gave us in the section of openGL and i want to run it under Linux (it worked under windows), i searched about openGL and i downloaded some packages for openGL and also tried a code from the Internet that makes a 3d box a u can rotate using mouse and it worked smoothly, and BTW i am on ubuntu 64, so if any body can help me, and thx in advance
and here is the output from the compilation
$ g++ use_keyboard_v1.cpp -o out
use_keyboard_v1.cpp:1:21: error: windows.h: No such file or directory
use_keyboard_v1.cpp:2:20: error: gl/Glu.h: No such file or directory
use_keyboard_v1.cpp:3:21: error: gl/glut.h: No such file or directory
use_keyboard_v1.cpp: In function ‘void myInit()’:
use_keyboard_v1.cpp:7: error: ‘glPointSize’ was not declared in this scope
use_keyboard_v1.cpp:8: error: ‘glColor3f’ was not declared in this scope
use_keyboard_v1.cpp:9: error: ‘glClearColor’ was not declared in this scope
use_keyboard_v1.cpp:11: error: ‘GL_PROJECTION’ was not declared in this scope
use_keyboard_v1.cpp:11: error: ‘glMatrixMode’ was not declared in this scope
use_keyboard_v1.cpp:12: error: ‘glLoadIdentity’ was not declared in this scope
use_keyboard_v1.cpp:13: error: ‘gluOrtho2D’ was not declared in this scope
use_keyboard_v1.cpp: In function ‘void myDisplay()’:
use_keyboard_v1.cpp:19: error: ‘GL_COLOR_BUFFER_BIT’ was not declared in this scope
use_keyboard_v1.cpp:19: error: ‘glClear’ was not declared in this scope
use_keyboard_v1.cpp:21: error: ‘glFlush’ was not declared in this scope
use_keyboard_v1.cpp: In function ‘void myKeyboard(unsigned char, int, int)’:
use_keyboard_v1.cpp:29: error: ‘GL_POINTS’ was not declared in this scope
use_keyboard_v1.cpp:29: error: ‘glBegin’ was not declared in this scope
use_keyboard_v1.cpp:30: error: ‘glVertex2i’ was not declared in this scope
use_keyboard_v1.cpp:31: error: ‘glEnd’ was not declared in this scope
use_keyboard_v1.cpp:34: error: ‘glColor3f’ was not declared in this scope
use_keyboard_v1.cpp:36: error: ‘glColor3f’ was not declared in this scope
use_keyboard_v1.cpp:38: error: ‘glColor3f’ was not declared in this scope
use_keyboard_v1.cpp:41: error: ‘GL_COLOR_BUFFER_BIT’ was not declared in this scope
use_keyboard_v1.cpp:41: error: ‘glClear’ was not declared in this scope
use_keyboard_v1.cpp:42: error: ‘glFlush’ was not declared in this scope
use_keyboard_v1.cpp: In function ‘void myMouse(int, int, int, int)’:
use_keyboard_v1.cpp:47: error: ‘GLUT_LEFT_BUTTON’ was not declared in this scope
use_keyboard_v1.cpp:47: error: ‘GLUT_DOWN’ was not declared in this scope
use_keyboard_v1.cpp:49: error: ‘GL_POINTS’ was not declared in this scope
use_keyboard_v1.cpp:49: error: ‘glBegin’ was not declared in this scope
use_keyboard_v1.cpp:50: error: ‘glVertex2i’ was not declared in this scope
use_keyboard_v1.cpp:51: error: ‘glEnd’ was not declared in this scope
use_keyboard_v1.cpp:53: error: ‘GLUT_RIGHT_BUTTON’ was not declared in this scope
use_keyboard_v1.cpp:55: error: ‘glFlush’ was not declared in this scope
use_keyboard_v1.cpp: In function ‘void myPassiveMotion(int, int)’:
use_keyboard_v1.cpp:64: error: ‘GL_POINTS’ was not declared in this scope
use_keyboard_v1.cpp:64: error: ‘glBegin’ was not declared in this scope
use_keyboard_v1.cpp:65: error: ‘glVertex2i’ was not declared in this scope
use_keyboard_v1.cpp:66: error: ‘glEnd’ was not declared in this scope
use_keyboard_v1.cpp:67: error: ‘glFlush’ was not declared in this scope
use_keyboard_v1.cpp: At global scope:
use_keyboard_v1.cpp:71: error: ‘::main’ must return ‘int’
use_keyboard_v1.cpp: In function ‘int main(int, char**)’:
use_keyboard_v1.cpp:73: error: ‘glutInit’ was not declared in this scope
use_keyboard_v1.cpp:74: error: ‘GLUT_SINGLE’ was not declared in this scope
use_keyboard_v1.cpp:74: error: ‘GLUT_RGB’ was not declared in this scope
use_keyboard_v1.cpp:74: error: ‘glutInitDisplayMode’ was not declared in this scope
use_keyboard_v1.cpp:75: error: ‘glutInitWindowSize’ was not declared in this scope
use_keyboard_v1.cpp:76: error: ‘glutInitWindowPosition’ was not declared in this scope
use_keyboard_v1.cpp:77: error: ‘glutCreateWindow’ was not declared in this scope
use_keyboard_v1.cpp:80: error: ‘glutDisplayFunc’ was not declared in this scope
use_keyboard_v1.cpp:81: error: ‘glutMouseFunc’ was not declared in this scope
use_keyboard_v1.cpp:82: error: ‘glutKeyboardFunc’ was not declared in this scope
use_keyboard_v1.cpp:83: error: ‘glutMotionFunc’ was not declared in this scope
use_keyboard_v1.cpp:84: error: ‘glutPassiveMotionFunc’ was not declared in this scope
use_keyboard_v1.cpp:87: error: ‘glutMainLoop’ was not declared in this scope