CMassView::CMassView(BRect frame, const char *name, struct picture* newBitmaps) // constructor : BGLView(frame, name, B_FOLLOW_ALL, B_FULL_UPDATE_ON_RESIZE, BGL_RGB | BGL_DEPTH | BGL_DOUBLE)// call inherited constructor { CELL_SIZE = 63; theBitmaps = newBitmaps; // save a pointer to the bitmaps acceptClicks = false; // and ignore any clicks inGLMode = false; // start off NOT in GL mode xRot = 0.6; yRot = 0.8; zRot = 0.0; // direction vector for rotation scale = 25.0; offset_x = 0.0; offset_y = 0.0; // allows us to move the object around laterally dragMode = dragBall; // start off in dragBall mode Ball_Init(&ball); // initialize the arcball Ball_Place(&ball, qOne, 0.75); // place the arcball (at 3/4 of window size) SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); } // end of CMassView constructor
/******************************************************************************* Function that performs most of the OpenGL intialization. *******************************************************************************/ void myinit(void) { GLfloat ambient[] = { 0.2, 0.2, 0.2, 1.0 }; GLfloat diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat specular[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat position[] = { 0.0, 0.0, 30.0, 1.0 }; GLfloat diffuse2[] = { 0.3, 0.3, 0.3, 1.0 }; GLfloat specular2[] = { 0.3, 0.3, 0.3, 1.0 }; GLfloat position2[] = { 0.0, 100.0, 00.0, 1.0 }; GLfloat lmodel_ambient[] = { 0.2f, 0.2f, 0.2f, 1.0f }; GLfloat local_view[] = { 0.0 }; /**** Set lighting parameters ****/ glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, specular); glLightf(GL_LIGHT0, GL_SHININESS, 100) ; glLightfv(GL_LIGHT0, GL_POSITION, position); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE) ; glLightfv(GL_LIGHT1, GL_AMBIENT, ambient); glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse2); glLightfv(GL_LIGHT1, GL_SPECULAR, specular2); glLightfv(GL_LIGHT1, GL_POSITION, position2); glLightf(GL_LIGHT1, GL_SHININESS, 500) ; glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glEnable(GL_AUTO_NORMAL); glEnable(GL_NORMALIZE); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glPixelStorei(GL_PACK_ALIGNMENT,1); glPixelStorei(GL_UNPACK_ALIGNMENT,1); glShadeModel(GL_SMOOTH); g_arcBall = new BallData; Ball_Init(g_arcBall); Ball_Place(g_arcBall,qOne,0.75); }
void Init(void) { GLfloat ambient[] = { 0.2, 0.2, 0.2, 1.0 }; GLfloat diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat specular[] = { 1.0, 1.0, 1.0, 1.0 }; //GLfloat position[] = { -3.0, 3.0, 3.0, 0.0 }; GLfloat position[] = { 0.0, 0.0, 1.0, 0 }; GLfloat lmodel_ambient[] = { 0.2f, 0.2f, 0.2f, 1.0f }; GLfloat local_view[] = { 0.0 }; /**** set lighting parameters ****/ glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT0, GL_POSITION, position); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE) ; /* glFrontFace (GL_CW); */ glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_AUTO_NORMAL); glEnable(GL_NORMALIZE); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glPixelStorei(GL_PACK_ALIGNMENT,1) ; glPixelStorei(GL_UNPACK_ALIGNMENT,1) ; glShadeModel(GL_SMOOTH) ; g_arcball = new BallData ; Ball_Init(g_arcball); Ball_Place(g_arcball,qOne,0.75); glViewport(0, 0, g_width, g_height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); //glFrustum(-5,5,-5,5,4,100); glOrtho(-6,6,-6,6,-500,500) ; myOpenGLInit() ; }
// this function gets caled for any keypresses void myKey(unsigned char key, int x, int y) { float time ; switch (key) { case 'q': case 27: exit(0); case 's': FrSaver.DumpPPM(Width,Height) ; break; case 'r': Ball_Init(Arcball); // reset arcball Ball_Place(Arcball,qOne,0.75); glutPostRedisplay() ; break ; case 'a': // toggle animation Animate = 1 - Animate ; // reset the timer to point to the current time time = TM.GetElapsedTime() ; TM.Reset() ; // printf("Elapsed time %f\n", time) ; break ; case '0': //reset your object break ; case 'm': if( Recording == 1 ) { printf("Frame recording disabled.\n") ; Recording = 0 ; } else { printf("Frame recording enabled.\n") ; Recording = 1 ; } FrSaver.Toggle(Width); break ; case 'h': case '?': instructions(); break; } glutPostRedisplay() ; }
// Performs most of the OpenGL intialization -- change these with care, if you must. void myinit(void) { #ifndef EMSCRIPTEN GLuint program = InitShader( "../my code/vshader.glsl", "../my code/fshader.glsl" ); // Load shaders and use the resulting shader program #else GLuint program = InitShader( "vshader.glsl", "fshader.glsl" ); // Load shaders and use the resulting shader program #endif glUseProgram(program); // Generate vertex arrays for geometric shapes generateCube(program, &cubeData); generateSphere(program, &sphereData); generateCone(program, &coneData); generateCylinder(program, &cylData); uModelView = glGetUniformLocation( program, "ModelView" ); uProjection = glGetUniformLocation( program, "Projection" ); uView = glGetUniformLocation( program, "View" ); glClearColor( 0.1, 0.1, 0.2, 1.0 ); // dark blue background uAmbient = glGetUniformLocation( program, "AmbientProduct" ); uDiffuse = glGetUniformLocation( program, "DiffuseProduct" ); uSpecular = glGetUniformLocation( program, "SpecularProduct" ); uLightPos = glGetUniformLocation( program, "LightPosition" ); uShininess = glGetUniformLocation( program, "Shininess" ); uTex = glGetUniformLocation( program, "Tex" ); uEnableTex = glGetUniformLocation( program, "EnableTex" ); glUniform4f(uAmbient, 0.2f, 0.2f, 0.2f, 1.0f); glUniform4f(uDiffuse, 0.6f, 0.6f, 0.6f, 1.0f); glUniform4f(uSpecular, 0.2f, 0.2f, 0.2f, 1.0f); glUniform4f(uLightPos, 15.0f, 15.0f, 30.0f, 0.0f); glUniform1f(uShininess, 100.0f); glEnable(GL_DEPTH_TEST); Arcball = new BallData; Ball_Init(Arcball); Ball_Place(Arcball,qOne,0.75); }
void resetArcball() { Ball_Init(Arcball); Ball_Place(Arcball,qOne,0.75); }
void myinit(void) { // Load shaders and use the resulting shader program GLuint program = InitShader( "vshader.glsl", "fshader.glsl" ); glUseProgram(program); // Generate vertex arrays for geometric shapes generateCube(program, &cubeData); generateSphere(program, &sphereData); generateCone(program, &coneData); generateCylinder(program, &cylData); generatePyramid(program, &pyramidData); uModelView = glGetUniformLocation( program, "ModelView" ); uProjection = glGetUniformLocation( program, "Projection" ); uView = glGetUniformLocation( program, "View" ); glClearColor( .1, .1, .6, 1.0 ); // dark blue background uAmbient = glGetUniformLocation( program, "AmbientProduct" ); uDiffuse = glGetUniformLocation( program, "DiffuseProduct" ); uSpecular = glGetUniformLocation( program, "SpecularProduct" ); uLightPos = glGetUniformLocation( program, "LightPosition" ); uShininess = glGetUniformLocation( program, "Shininess" ); uTex = glGetUniformLocation( program, "Tex" ); uEnableTex = glGetUniformLocation( program, "EnableTex" ); glUniform4f(uAmbient, 0.2f, 0.2f, 0.2f, 1.0f); glUniform4f(uDiffuse, 0.6f, 0.6f, 0.6f, 1.0f); glUniform4f(uSpecular, 0.2f, 0.2f, 0.2f, 1.0f); glUniform4f(uLightPos, 15.0f, 15.0f, 30.0f, 0.0f); glUniform1f(uShininess, 100.0f); glEnable(GL_DEPTH_TEST); TgaImage coolImage; if (!coolImage.loadTGA("dirt.tga")) { printf("Error loading image file\n"); exit(1); } TgaImage earthImage; if (!earthImage.loadTGA("earth.tga")) { printf("Error loading image file\n"); exit(1); } TgaImage roofImage; if (!roofImage.loadTGA("roof.tga")) { printf("Error loading image file\n"); exit(1); } TgaImage treeImage; if (!treeImage.loadTGA("tree.tga")) { printf("Error loading image file\n"); exit(1); } TgaImage skyImage; if (!skyImage.loadTGA("sky.tga")) { printf("Error loading image file\n"); exit(1); } TgaImage stoneImage; if (!stoneImage.loadTGA("stone.tga")) { printf("Error loading image file\n"); exit(1); } TgaImage leafImage; if (!leafImage.loadTGA("leaf.tga")) { printf("Error loading image file\n"); exit(1); } glGenTextures( 1, &texture_cube ); glBindTexture( GL_TEXTURE_2D, texture_cube ); glTexImage2D(GL_TEXTURE_2D, 0, 4, coolImage.width, coolImage.height, 0, (coolImage.byteCount == 3) ? GL_BGR : GL_BGRA, GL_UNSIGNED_BYTE, coolImage.data ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glGenTextures( 1, &texture_earth ); glBindTexture( GL_TEXTURE_2D, texture_earth ); glTexImage2D(GL_TEXTURE_2D, 0, 4, earthImage.width, earthImage.height, 0, (earthImage.byteCount == 3) ? GL_BGR : GL_BGRA, GL_UNSIGNED_BYTE, earthImage.data ); //roof glGenTextures( 1, &texture_roof ); glBindTexture( GL_TEXTURE_2D, texture_roof ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexImage2D(GL_TEXTURE_2D, 0, 4, roofImage.width, roofImage.height, 0, (roofImage.byteCount == 3) ? GL_BGR : GL_BGRA, GL_UNSIGNED_BYTE, roofImage.data ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glGenTextures( 1, &texture_trees ); glBindTexture( GL_TEXTURE_2D, texture_trees ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexImage2D(GL_TEXTURE_2D, 0, 4, treeImage.width, treeImage.height, 0, (treeImage.byteCount == 3) ? GL_BGR : GL_BGRA, GL_UNSIGNED_BYTE, treeImage.data ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glGenTextures( 1, &texture_leaf ); glBindTexture( GL_TEXTURE_2D, texture_leaf ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexImage2D(GL_TEXTURE_2D, 0, 4, leafImage.width, leafImage.height, 0, (leafImage.byteCount == 3) ? GL_BGR : GL_BGRA, GL_UNSIGNED_BYTE, leafImage.data ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glGenTextures( 1, &texture_stone ); glBindTexture( GL_TEXTURE_2D, texture_stone ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexImage2D(GL_TEXTURE_2D, 0, 4, stoneImage.width, stoneImage.height, 0, (stoneImage.byteCount == 3) ? GL_BGR : GL_BGRA, GL_UNSIGNED_BYTE, stoneImage.data ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); // Set texture sampler variable to texture unit 0 // (set in glActiveTexture(GL_TEXTURE0)) glUniform1i( uTex, 0); Arcball = new BallData; Ball_Init(Arcball); Ball_Place(Arcball,qOne,0.75); }
void myinit(void) { // Load shaders and use the resulting shader program GLuint program = InitShader( "vshader.glsl", "fshader.glsl" ); glUseProgram(program); // Generate vertex arrays for geometric shapes generateGrass(program, &grassData); generateHeart(program, &heartData); generateCube(program, &cubeData); generateSphere(program, &sphereData); generateCone(program, &coneData); generateCylinder(program, &cylData); uModelView = glGetUniformLocation( program, "ModelView" ); uProjection = glGetUniformLocation( program, "Projection" ); uView = glGetUniformLocation( program, "View" ); glClearColor( 0.5, 0.5, 1.0, 1.0 ); // dark blue background uAmbient = glGetUniformLocation( program, "AmbientProduct" ); uDiffuse = glGetUniformLocation( program, "DiffuseProduct" ); uSpecular = glGetUniformLocation( program, "SpecularProduct" ); uLightPos = glGetUniformLocation( program, "LightPosition" ); uShininess = glGetUniformLocation( program, "Shininess" ); uTex = glGetUniformLocation( program, "Tex" ); uEnableTex = glGetUniformLocation( program, "EnableTex" ); glUniform4f(uAmbient, 0.2f, 0.2f, 0.2f, 1.0f); glUniform4f(uDiffuse, 0.6f, 0.6f, 0.6f, 1.0f); glUniform4f(uSpecular, 0.2f, 0.2f, 0.2f, 1.0f); glUniform4f(uLightPos, 15.0f, 15.0f, 30.0f, 0.0f); glUniform1f(uShininess, 100.0f); glEnable(GL_DEPTH_TEST); TgaImage coolImage; if (!coolImage.loadTGA("challenge.tga")) { printf("Error loading image file\n"); exit(1); } GLuint texture; glGenTextures( 1, &texture ); glBindTexture( GL_TEXTURE_2D, texture ); glTexImage2D(GL_TEXTURE_2D, 0, 4, coolImage.width, coolImage.height, 0, (coolImage.byteCount == 3) ? GL_BGR : GL_BGRA, GL_UNSIGNED_BYTE, coolImage.data ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glActiveTexture( GL_TEXTURE0 ); glBindTexture( GL_TEXTURE_2D, texture ); // Set texture sampler variable to texture unit 0 // (set in glActiveTexture(GL_TEXTURE0)) glUniform1i( uTex, 0 ); Arcball = new BallData ; Ball_Init(Arcball); Ball_Place(Arcball,qOne,0.75); }