void Platform::Draw () { glPushMatrix(); GLuint list = MakeCube(pos.x, pos.y, pos.z); glCallList(list); glDeleteLists(list, 1); glPopMatrix(); }
void RNCubeExample::Prepare(Wz4RenderContext *ctx) { // create vertex buffer here per frame. // it might be used multiple times. MakeCube(); // this is the right place for complicated math sSRT srt; srt.Scale = Para.Scale; srt.Rotate = Para.Rot*sPI2F; srt.Translate = Para.Trans; srt.MakeMatrix(Matrix); if(Mtrl) Mtrl->BeforeFrame(Para.EnvNum); }
void Mesh::MakeMesh(MeshType type, uint steps) { switch (type) { case MeshType::MeshTypeCube: MakeCube(); break; case MeshType::MeshTypeCylinder: MakeCylinder(steps); break; case MeshType::MeshTypeSphere: MakeSphere(steps); break; default: Trace::WriteLine(String::Format("Unknown mesh type:{0}", type)); break; } }
void main(int argc, char *argv[]) { int i; #ifdef IRIX_5_1_MOTIF_BUG_WORKAROUND /* * XXX Unfortunately a bug in the IRIX 5.1 Motif shared library * causes a BadMatch X protocol error if the SGI look&feel * is enabled for this program. If we detect we are on an * IRIX 5.1 system, skip the first two fallback resources which * specify using the SGI look&feel. */ struct utsname versionInfo; if(uname(&versionInfo) >= 0) { if(!strcmp(versionInfo.sysname, "IRIX") && !strncmp(versionInfo.release, "5.1", 3)) { toplevel = XtAppInitialize(&app, "Textfun", NULL, 0, &argc, argv, &fallbackResources[2], NULL, 0); } } if(toplevel == NULL) { toplevel = XtAppInitialize(&app, "Textfun", NULL, 0, &argc, argv, fallbackResources, NULL, 0); } #else toplevel = XtAppInitialize(&app, "Textfun", NULL, 0, &argc, argv, fallbackResources, NULL, 0); #endif dpy = XtDisplay(toplevel); /* find an OpenGL-capable RGB visual with depth buffer */ vi = glXChooseVisual(dpy, DefaultScreen(dpy), dblBuf); if (vi == NULL) { vi = glXChooseVisual(dpy, DefaultScreen(dpy), snglBuf); if (vi == NULL) XtAppError(app, "no RGB visual with depth buffer"); doubleBuffer = GL_FALSE; } for (i = 0; i < NUM_FONT_ENTRIES; i++) { fontEntry[i].xfont = XLoadQueryFont(dpy, fontEntry[i].xlfd); if (i == 0 && !fontEntry[i].xfont) XtAppError(app, "could not get basic font"); } fontEntry[0].fontinfo = SuckGlyphsFromServer(dpy, fontEntry[0].xfont->fid); if (!fontEntry[0].fontinfo) XtAppError(app, "could not get font glyphs"); /* create an OpenGL rendering context */ cx = glXCreateContext(dpy, vi, /* no display list sharing */ None, /* favor direct */ GL_TRUE); if (cx == NULL) XtAppError(app, "could not create rendering context"); /* create an X colormap since probably not using default visual */ cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual, AllocNone); XtVaSetValues(toplevel, XtNvisual, vi->visual, XtNdepth, vi->depth, XtNcolormap, cmap, NULL); XtAddEventHandler(toplevel, StructureNotifyMask, False, map_state_changed, NULL); mainw = XmCreateMainWindow(toplevel, "mainw", NULL, 0); XtManageChild(mainw); /* create menu bar */ menubar = XmCreateMenuBar(mainw, "menubar", NULL, 0); XtManageChild(menubar); /* hack around Xt's ignorance of visuals */ XtSetArg(menuPaneArgs[0], XmNdepth, DefaultDepthOfScreen(XtScreen(mainw))); XtSetArg(menuPaneArgs[1], XmNcolormap, DefaultColormapOfScreen(XtScreen(mainw))); /* create File pulldown menu: Quit */ menupane = XmCreatePulldownMenu(menubar, "menupane", menuPaneArgs, 2); btn = XmCreatePushButton(menupane, "Quit", NULL, 0); XtAddCallback(btn, XmNactivateCallback, quit, NULL); XtManageChild(btn); XtSetArg(args[0], XmNsubMenuId, menupane); cascade = XmCreateCascadeButton(menubar, "File", args, 1); XtManageChild(cascade); /* create Options pulldown menu: Motion, Dolly, Rotate, Wobble */ menupane = XmCreatePulldownMenu(menubar, "menupane", menuPaneArgs, 2); btn = XmCreateToggleButton(menupane, "Motion", NULL, 0); XtAddCallback(btn, XmNvalueChangedCallback, (XtCallbackProc) toggle, NULL); XtManageChild(btn); btn = XmCreateToggleButton(menupane, "Dolly", NULL, 0); XtAddCallback(btn, XmNvalueChangedCallback, (XtCallbackProc) dolly, NULL); XtVaSetValues(btn, XmNset, True, NULL); XtManageChild(btn); btn = XmCreateToggleButton(menupane, "Rotate", NULL, 0); XtAddCallback(btn, XmNvalueChangedCallback, (XtCallbackProc) rotate, NULL); XtManageChild(btn); btn = XmCreateToggleButton(menupane, "Wobble", NULL, 0); XtAddCallback(btn, XmNvalueChangedCallback, (XtCallbackProc) wobble, NULL); XtManageChild(btn); XtSetArg(args[0], XmNsubMenuId, menupane); cascade = XmCreateCascadeButton(menubar, "Options", args, 1); XtManageChild(cascade); XtSetArg(menuPaneArgs[2], XmNradioBehavior, True); XtSetArg(menuPaneArgs[3], XmNradioAlwaysOne, True); menupane = XmCreatePulldownMenu(menubar, "menupane", menuPaneArgs, 4); XtAddCallback(menupane, XmNentryCallback, (XtCallbackProc) fontSelect, NULL); for (i = 0; i < NUM_FONT_ENTRIES; i++) { btn = XmCreateToggleButton(menupane, fontEntry[i].name, NULL, 0); XtAddCallback(btn, XmNvalueChangedCallback, (XtCallbackProc) neverCalled, &fontEntry[i]); if (i == 0) XtVaSetValues(btn, XmNset, True, NULL); if (!fontEntry[i].xfont) XtSetSensitive(btn, False); XtManageChild(btn); } XtSetArg(args[0], XmNsubMenuId, menupane); cascade = XmCreateCascadeButton(menubar, "Font", args, 1); XtManageChild(cascade); /* create framed drawing area for OpenGL rendering */ frame = XmCreateFrame(mainw, "frame", NULL, 0); XtManageChild(frame); glxarea = XtCreateManagedWidget("glxarea", xmDrawingAreaWidgetClass, frame, NULL, 0); XtAddCallback(glxarea, XmNexposeCallback, (XtCallbackProc) draw, NULL); XtAddCallback(glxarea, XmNresizeCallback, resize, NULL); XtAddCallback(glxarea, XmNinputCallback, input, NULL); /* set up application's window layout */ XmMainWindowSetAreas(mainw, menubar, NULL, NULL, NULL, frame); XtRealizeWidget(toplevel); /* * Once widget is realized (ie, associated with a created X window), we * can bind the OpenGL rendering context to the window. */ glXMakeCurrent(dpy, XtWindow(glxarea), cx); made_current = GL_TRUE; /* setup OpenGL state */ glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glClearDepth(1.0); glMatrixMode(GL_PROJECTION); glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 80); glMatrixMode(GL_MODELVIEW); MakeCube(); if (argv[1] != NULL) { numMessages = argc - 1; messages = &argv[1]; } else { numMessages = NUM_DEFAULT_MESSAGES; messages = defaultMessage; } base = glGenLists(numMessages + 1); SetupMessageDisplayList(&fontEntry[0], numMessages, messages); tick(); /* start event processing */ XtAppMainLoop(app); }
/////////////////////////////////////////////////////////////////////////////// // This function does any needed initialization on the rendering context. // This is the first opportunity to do any OpenGL related tasks. void SetupRC() { GLbyte *pBytes; GLint nWidth, nHeight, nComponents; GLenum format; shaderManager.InitializeStockShaders(); // Black background glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); glEnable(GL_DEPTH_TEST); glLineWidth(2.5f); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix); cameraFrame.MoveForward(-15.0f); cameraFrame.MoveUp(6.0f); cameraFrame.RotateLocalX(float(m3dDegToRad(20.0f))); MakeCube(cubeBatch); MakeFloor(floorBatch); // Make top topBlock.Begin(GL_TRIANGLE_FAN, 4, 1); topBlock.Normal3f(0.0f, 1.0f, 0.0f); topBlock.MultiTexCoord2f(0, 0.0f, 0.0f); topBlock.Vertex3f(-1.0f, 1.0f, 1.0f); topBlock.Normal3f(0.0f, 1.0f, 0.0f); topBlock.MultiTexCoord2f(0, 1.0f, 0.0f); topBlock.Vertex3f(1.0f, 1.0f, 1.0f); topBlock.Normal3f(0.0f, 1.0f, 0.0f); topBlock.MultiTexCoord2f(0, 1.0f, 1.0f); topBlock.Vertex3f(1.0f, 1.0f, -1.0f); topBlock.Normal3f(0.0f, 1.0f, 0.0f); topBlock.MultiTexCoord2f(0, 0.0f, 1.0f); topBlock.Vertex3f(-1.0f, 1.0f, -1.0f); topBlock.End(); // Make Front frontBlock.Begin(GL_TRIANGLE_FAN, 4, 1); frontBlock.Normal3f(0.0f, 0.0f, 1.0f); frontBlock.MultiTexCoord2f(0, 0.0f, 0.0f); frontBlock.Vertex3f(-1.0f, -1.0f, 1.0f); frontBlock.Normal3f(0.0f, 0.0f, 1.0f); frontBlock.MultiTexCoord2f(0, 1.0f, 0.0f); frontBlock.Vertex3f(1.0f, -1.0f, 1.0f); frontBlock.Normal3f(0.0f, 0.0f, 1.0f); frontBlock.MultiTexCoord2f(0, 1.0f, 1.0f); frontBlock.Vertex3f(1.0f, 1.0f, 1.0f); frontBlock.Normal3f(0.0f, 0.0f, 1.0f); frontBlock.MultiTexCoord2f(0, 0.0f, 1.0f); frontBlock.Vertex3f(-1.0f, 1.0f, 1.0f); frontBlock.End(); // Make left leftBlock.Begin(GL_TRIANGLE_FAN, 4, 1); leftBlock.Normal3f(-1.0f, 0.0f, 0.0f); leftBlock.MultiTexCoord2f(0, 0.0f, 0.0f); leftBlock.Vertex3f(-1.0f, -1.0f, -1.0f); leftBlock.Normal3f(-1.0f, 0.0f, 0.0f); leftBlock.MultiTexCoord2f(0, 1.0f, 0.0f); leftBlock.Vertex3f(-1.0f, -1.0f, 1.0f); leftBlock.Normal3f(-1.0f, 0.0f, 0.0f); leftBlock.MultiTexCoord2f(0, 1.0f, 1.0f); leftBlock.Vertex3f(-1.0f, 1.0f, 1.0f); leftBlock.Normal3f(-1.0f, 0.0f, 0.0f); leftBlock.MultiTexCoord2f(0, 0.0f, 1.0f); leftBlock.Vertex3f(-1.0f, 1.0f, -1.0f); leftBlock.End(); // Create shadow projection matrix GLfloat floorPlane[] = { 0.0f, 1.0f, 0.0f, 1.0f}; m3dMakePlanarShadowMatrix(shadowMatrix, floorPlane, vLightPos); // Load up four textures glGenTextures(4, textures); // Wood floor pBytes = gltReadTGABits("floor.tga", &nWidth, &nHeight, &nComponents, &format); glBindTexture(GL_TEXTURE_2D, textures[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0, format, GL_UNSIGNED_BYTE, pBytes); free(pBytes); // One of the block faces pBytes = gltReadTGABits("Block4.tga", &nWidth, &nHeight, &nComponents, &format); glBindTexture(GL_TEXTURE_2D, textures[1]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0, format, GL_UNSIGNED_BYTE, pBytes); free(pBytes); // Another block face pBytes = gltReadTGABits("block5.tga", &nWidth, &nHeight, &nComponents, &format); glBindTexture(GL_TEXTURE_2D, textures[2]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0, format, GL_UNSIGNED_BYTE, pBytes); free(pBytes); // Yet another block face pBytes = gltReadTGABits("block6.tga", &nWidth, &nHeight, &nComponents, &format); glBindTexture(GL_TEXTURE_2D, textures[3]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0, format, GL_UNSIGNED_BYTE, pBytes); free(pBytes); }
//--------------------------------------------------------------------------- double DoRInterpolation(double r, double g, double b) { double x1,y1,z1; double x2,y2,z2; double x3,y3,z3; double x4,y4,z4; double g1, g2, e1, e2; TColorTable ct[8]; MakeCube(r,g,b, ct); x1 = ct[0].BM; y1 = ct[0].RM; z1 = ct[0].GM; x2 = ct[7].BM; y2 = ct[7].RM; z2 = ct[7].GM; x3 = ct[3].BM; y3 = ct[3].RM; z3 = ct[3].GM; x4 = ct[5].BM; y4 = ct[5].RM; z4 = ct[5].GM; g1 = PlaneInterpolaton(x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4,b,r); z1 = ct[0].R - ct[0].RM; z2 = ct[7].R - ct[7].RM; z3 = ct[3].R - ct[3].RM; z4 = ct[5].R - ct[5].RM; e1 = PlaneInterpolaton(x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4,b,r); x1 = ct[6].BM; y1 = ct[6].RM; z1 = ct[6].GM; x2 = ct[2].BM; y2 = ct[2].RM; z2 = ct[2].GM; x3 = ct[1].BM; y3 = ct[1].RM; z3 = ct[1].GM; x4 = ct[4].BM; y4 = ct[4].RM; z4 = ct[4].GM; g2 = PlaneInterpolaton(x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4,b,r); z1 = ct[6].R - ct[6].RM; z2 = ct[2].R - ct[2].RM; z3 = ct[1].R - ct[1].RM; z4 = ct[4].R - ct[4].RM; e2 = PlaneInterpolaton(x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4,b,r); return Interpolation(g1,g2,e1,e2, g); }