static void draw_ball(void) { GLfloat a, b; GLfloat da = 18.0, db = 18.0; GLfloat radius = 1.0; GLuint color; GLfloat x, y, z; color = 0; for (a = -90.0; a+da <= 90.0; a += da) { glBegin(GL_QUAD_STRIP); for (b = 0.0; b <=360.0 ; b += db) { if (color) glIndexf(4); else glIndexf(15); x = COS(b) * COS(a); y = SIN(b) * COS(a); z = SIN(a); glVertex3f(x, y, z); x = radius * COS(b) * COS(a+da); y = radius * SIN(b) * COS(a+da); z = radius * SIN(a+da); glVertex3f(x, y, z); color = 1 - color; } glEnd(); } }
static void Idle(void) { if (overlayInit == GL_FALSE) { glutUseLayer(GLUT_OVERLAY); glClear(GL_COLOR_BUFFER_BIT); /* glColor3f(1.0, 0.0, 0.0);*/ glIndexf( 2.0 ); glBegin(GL_POLYGON); glVertex2i(windW/4-10, windH/4-10); glVertex2i(windW/2-10, windH/4-10); glVertex2i(windW/2-10, windH/2-10); glVertex2i(windW/4-10, windH/2-10); glEnd(); glIndexf( 0.0 ); glBegin(GL_POLYGON); glVertex2i(windW/4, windH/4); glVertex2i(windW/2, windH/4); glVertex2i(windW/2, windH/2); glVertex2i(windW/4, windH/2); glEnd(); glIndexf( 1.0 ); glBegin(GL_POLYGON); glVertex2i(windW/4+10, windH/4+10); glVertex2i(windW/2+10, windH/4+10); glVertex2i(windW/2+10, windH/2+10); glVertex2i(windW/4+10, windH/2+10); glEnd(); glutUseLayer(GLUT_NORMAL); overlayInit = GL_TRUE; } MoveStars(); ShowStars(); if (nitro > 0) { speed = (float)(nitro / 10) + 1.0; if (speed > MAXWARP) { speed = MAXWARP; } if (++nitro > MAXWARP*10) { nitro = -nitro; } } else if (nitro < 0) { nitro++; speed = (float)(-nitro / 10) + 1.0; if (speed > MAXWARP) { speed = MAXWARP; } } glFlush(); if (doubleBuffer) { glutSwapBuffers(); } }
static void move_on(void) { display_count++; if (display_count == 2) { damage_expectation = 1; glutIconifyWindow(); glutTimerFunc(500, timer, 777); } if (display_count == 4) { printf("display_count == 4\n"); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutCreateSubWindow(main_win, 10, 10, 150, 150); glClearColor(0.5, 0.5, 0.5, 0.0); glutDisplayFunc(render_sub); glutInitDisplayMode(GLUT_SINGLE | GLUT_INDEX); glutEstablishOverlay(); glutCopyColormap(main_win); glutSetColor((transP + 1) % 2, 0.0, 1.0, 1.0); glutRemoveOverlay(); glutEstablishOverlay(); glutCopyColormap(main_win); glutCopyColormap(main_win); glutSetColor((transP + 1) % 2, 1.0, 1.0, 1.0); glClearIndex(transP); glIndexf((transP + 1) % 2); glutSetWindow(main_win); glutRemoveOverlay(); glutTimerFunc(500, time2, 888); } }
static void SetColor(int c) { if (glutGet(GLUT_WINDOW_RGBA)) glColor3fv(RGBMap[c]); else glIndexf(c); }
/* ======================================================================================================================= sets the color of the next object to draw ======================================================================================================================= */ setColor(int c) { glColor4fv(&materialColor[c][0]); if(useLighting) { { if(useRGB) { glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, &materialColor[c][0]); } else { glMaterialfv(GL_FRONT_AND_BACK, GL_COLOR_INDEXES, &materialColor[c][0]); } } } else { if(useRGB) { glColor4fv(&materialColor[c][0]); } else { glIndexf(materialColor[c][1]); } } }
void setspherecolor(float c) { if (useci) { GLfloat ndx = c * (float)(ncolors - 1); GLfloat mat_ndxs[] = { ndx * 0.3f, ndx * 0.8f, ndx }; glIndexf(ndx); glMaterialfv(GL_FRONT, GL_COLOR_INDEXES, mat_ndxs); } else { float mat[4] = { spherered(c), spheregreen(c), sphereblue(c), 0.25f }; glColor3f(spherered(c), spheregreen(c), sphereblue(c)); glMaterialfv(GL_FRONT, GL_AMBIENT, mat); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat); } }
static void draw(void) { GLint i; glClear(GL_COLOR_BUFFER_BIT); glIndexf(3); glBegin(GL_LINES); for (i = -5; i <= 5; i++) { glVertex2i(i, -5); glVertex2i(i, 5); } for (i = -5; i <= 5; i++) { glVertex2i(-5,i); glVertex2i(5,i); } for (i = -5; i <= 5; i++) { glVertex2i(i, -5); glVertex2f(i*1.15, -5.9); } glVertex2f(-5.3, -5.35); glVertex2f(5.3, -5.35); glVertex2f(-5.75, -5.9); glVertex2f(5.75, -5.9); glEnd(); glFlush(); glPushMatrix(); glTranslatef(Xpos, Ypos, 0.0); glScalef(2.0, 2.0, 2.0); glRotatef(8.0, 0.0, 0.0, 1.0); glRotatef(90.0, 1.0, 0.0, 0.0); glRotatef(Zrot, 0.0, 0.0, 1.0); glCallList(Ball); glPopMatrix(); glFlush(); }
static void Animate(void) { struct coord *coord; struct facet *facet; float *lastColor; float *thisColor; GLint i, j; glClear(clearMask); if (nextFrame || !stepMode) { curFrame++; } if (curFrame >= theMesh.frames) { curFrame = 0; } if ((nextFrame || !stepMode) && spinMode) { glRotatef(5.0, 0.0, 0.0, 1.0); } nextFrame = 0; for (i = 0; i < theMesh.widthX; i++) { glBegin(GL_QUAD_STRIP); lastColor = NULL; for (j = 0; j < theMesh.widthY; j++) { facet = GETFACET(curFrame, i, j); if (!smooth && lighting) { glNormal3fv(facet->normal); } if (lighting) { if (rgb) { thisColor = facet->color; glColor3fv(facet->color); } else { thisColor = facet->color; glMaterialfv(GL_FRONT_AND_BACK, GL_COLOR_INDEXES, facet->color); } } else { if (rgb) { thisColor = facet->color; glColor3fv(facet->color); } else { thisColor = facet->color; glIndexf(facet->color[1]); } } if (!lastColor || (thisColor[0] != lastColor[0] && smooth)) { if (lastColor) { glEnd(); glBegin(GL_QUAD_STRIP); } coord = GETCOORD(curFrame, i, j); if (smooth && lighting) { glNormal3fv(coord->normal); } glVertex3fv(coord->vertex); coord = GETCOORD(curFrame, i+1, j); if (smooth && lighting) { glNormal3fv(coord->normal); } glVertex3fv(coord->vertex); } coord = GETCOORD(curFrame, i, j+1); if (smooth && lighting) { glNormal3fv(coord->normal); } glVertex3fv(coord->vertex); coord = GETCOORD(curFrame, i+1, j+1); if (smooth && lighting) { glNormal3fv(coord->normal); } glVertex3fv(coord->vertex); lastColor = thisColor; } glEnd(); } glFlush(); if (doubleBuffer) { glutSwapBuffers(); } }
///////////////////////////////////////////////////////// // Render // void GEMglIndexf :: render(GemState *state) { glIndexf (c); }
int display(SDL_Window *window, int advance) { static int first = 1; static double start = 0., elapsed = 0., mpixels = 0.; static unsigned long frames = 0; static char temps[256]; GLfloat xaspect, yaspect; if (first) { buildfont(); GLfloat id4[] = { 1., 1., 1., 1. }; GLfloat light0_amb[] = { 0.3f, 0.3f, 0.3f, 1.0f }; GLfloat light0_dif[] = { 0.8f, 0.8f, 0.8f, 1.0f }; GLfloat light0_pos[] = { 1., 1., 1., 0. }; spherelist = glGenLists(1); if (!(spherequad = gluNewQuadric())) _throw("Could not allocate GLU quadric object"); glNewList(spherelist, GL_COMPILE); gluSphere(spherequad, 1.3, slices, stacks); glEndList(); if (!locolor) { if (useci) { glMaterialf(GL_FRONT, GL_SHININESS, 50.); } else { glMaterialfv(GL_FRONT, GL_AMBIENT, id4); glMaterialfv(GL_FRONT, GL_DIFFUSE, id4); glMaterialfv(GL_FRONT, GL_SPECULAR, id4); glMaterialf(GL_FRONT, GL_SHININESS, 50.); glLightfv(GL_LIGHT0, GL_AMBIENT, light0_amb); glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_dif); glLightfv(GL_LIGHT0, GL_SPECULAR, id4); } glLightfv(GL_LIGHT0, GL_POSITION, light0_pos); glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 180.); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); } if (locolor) glShadeModel(GL_FLAT); else glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); SDL_snprintf(temps, 255, "Measuring performance ..."); first = 0; } if (advance) { z -= 0.5; if (z < -29.) { if (useci) { colorscheme = (colorscheme + 1) % NSCHEMES; _catch(setcolorscheme(window, ncolors, colorscheme)); } z = -3.5; } outer_angle += 0.1f; if (outer_angle > 360.0f) outer_angle -= 360.0f; middle_angle -= 0.37f; if (middle_angle < -360.0f) middle_angle += 360.0f; inner_angle += 0.63f; if (inner_angle > 360.0f) inner_angle -= 360.0f; lonesphere_color += 0.005f; if (lonesphere_color > 1.0f) lonesphere_color -= 1.0f; } if (usestereo) { renderspheres(GL_BACK_LEFT); renderspheres(GL_BACK_RIGHT); } else { renderspheres(GL_BACK); } glDrawBuffer(GL_BACK); glPushAttrib(GL_CURRENT_BIT); glPushAttrib(GL_LIST_BIT); glPushAttrib(GL_ENABLE_BIT); glDisable(GL_LIGHTING); if (useci) glIndexf(254.); else glColor3f(1., 1., 1.); xaspect = (GLfloat)width / (GLfloat)(min(width, height)); yaspect = (GLfloat)height / (GLfloat)(min(width, height)); glRasterPos3f(-0.95f * xaspect, -0.95f * yaspect, -1.5f); glListBase(fontlistbase); glCallLists((GLsizei)strlen(temps), GL_UNSIGNED_BYTE, temps); glPopAttrib(); glPopAttrib(); glPopAttrib(); SDL_GL_SwapWindow(window); if (start > 0.) { elapsed += rrtime() - start; frames++; totalframes++; mpixels += (double)width * (double)height / 1000000.; if (elapsed > benchtime || (maxframes && totalframes > maxframes)) { SDL_snprintf(temps, 255, "%f frames/sec - %f Mpixels/sec", (double)frames / elapsed, mpixels / elapsed); printf("%s\n", temps); elapsed = mpixels = 0.; frames = 0; } } if (maxframes && totalframes > maxframes) goto bailout; start = rrtime(); return 0; bailout: if (spherequad) { gluDeleteQuadric(spherequad); spherequad = NULL; } return -1; }
template< > inline void glIndex< float > ( float c ) { glIndexf(c); };
void glIndexfv(const GLfloat *c) { glIndexf(*c); }
M(void, glIndexf, jfloat c) { glIndexf(c); }