//---------------------------------------------------------------------------- void Render() { static int rotation = 0; /* Vertex 1 Vertex 2 Vertex 3*/ GLshort vertexArray[9] = {-25,-25,0, 25,-25,0, 0,25,0 }; GLubyte colorArray[12] = {255,0,0,0, 0,255,0,0, 0,0,255,0}; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatex(0, 0, FixedFromInt(-10)); glRotatex(FixedFromInt(rotation++), 0, ONE,0); //Enable the vertices array glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_SHORT, 0, vertexArray); //3 = XYZ coordinates, GL_SHORT = data type, 0 = 0 stride bytes //Enable the vertex color array glEnableClientState(GL_COLOR_ARRAY); glColorPointer(4,GL_UNSIGNED_BYTE, 0, colorArray); //4 = RGBA format, GL_UNSIGNED_BYTE = data type,0=0 stide bytes glDrawArrays(GL_TRIANGLES, 0, 3); /*We want draw triangles, 0 = first element(vertice), 3 = number of items (vertices) to draw from the array*/ glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); eglSwapBuffers(glesDisplay, glesSurface); }
Sphere3x ContSphereAverage (int iQuantity, const Vector3x* akPoint, const bool* abValid) { Sphere3x kSphere(Vector3x::ZERO,fixed(FIXED_ZERO)); int i; Vector3x kDiff; fixed fRadiusSqr; if (!abValid) { kSphere.Center = akPoint[0]; for (i = 1; i < iQuantity; i++) { kSphere.Center += akPoint[i]; } kSphere.Center /= FixedFromInt(iQuantity); for (i = 0; i < iQuantity; i++) { kDiff = akPoint[i] - kSphere.Center; fRadiusSqr = kDiff.SquaredLength(); if (fRadiusSqr > kSphere.Radius) { kSphere.Radius = fRadiusSqr; } } } else { int iValidQuantity = 0; for (i = 0; i < iQuantity; i++) { if (abValid[i]) { kSphere.Center += akPoint[i]; iValidQuantity++; } } if (iValidQuantity == 0) { kSphere.Radius = FIXED_NEG_ONE; return kSphere; } kSphere.Center /= FixedFromInt(iValidQuantity); for (i = 0; i < iQuantity; i++) { if (abValid[i]) { kDiff = akPoint[i] - kSphere.Center; fRadiusSqr = kDiff.SquaredLength(); if (fRadiusSqr > kSphere.Radius) { kSphere.Radius = fRadiusSqr; } } } } kSphere.Radius = Mathx::Sqrt(kSphere.Radius); return kSphere; }
//---------------------------------------------------------------------------- BOOL InitOGLES() { EGLConfig configs[10]; EGLint matchingConfigs; /*configAttribs is a integers list that holds the desired format of our framebuffer. We will ask for a framebuffer with 24 bits of color and 16 bits of z-buffer. We also ask for a window buffer, not a pbuffer or pixmap buffer*/ const EGLint configAttribs[] = { EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, EGL_DONT_CARE, EGL_DEPTH_SIZE, 16, EGL_STENCIL_SIZE, EGL_DONT_CARE, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_NONE, EGL_NONE }; hDC = GetWindowDC(hWnd); glesDisplay = eglGetDisplay(hDC); //Ask for an available display //Display initialization (we don't care about the OGLES version numbers) if(!eglInitialize(glesDisplay, NULL, NULL)) return FALSE; /*Ask for the framebuffer confiburation that best fits our parameters. At most, we want 10 configurations*/ if(!eglChooseConfig(glesDisplay, configAttribs, &configs[0], 10, &matchingConfigs)) return FALSE; //If there isn't any configuration enough good if (matchingConfigs < 1) return FALSE; /*eglCreateWindowSurface creates an onscreen EGLSurface and returns a handle to it. Any EGL rendering context created with a compatible EGLConfig can be used to render into this surface.*/ glesSurface = eglCreateWindowSurface(glesDisplay, configs[0], hWnd, configAttribs); if(!glesSurface) return FALSE; // Let's create our rendering context glesContext=eglCreateContext(glesDisplay,configs[0],0,configAttribs); if(!glesContext) return FALSE; //Now we will activate the context for rendering eglMakeCurrent(glesDisplay, glesSurface, glesSurface, glesContext); /*Remember: because we are programming for a mobile device, we cant use any of the OpenGL ES functions that finish in 'f', we must use the fixed point version (they finish in 'x'*/ glClearColorx(0, 0, 0, 0); glShadeModel(GL_SMOOTH); /*In order to set a viewport that fits entirely our window, we need to know the window dimensions. They could be obtained through the WinCE call GetWindowRect, using our window handle*/ RECT r; GetWindowRect(hWnd, &r); glViewport(r.left, r.top, r.right - r.left, r.bottom - r.top); /*Setup of the projection matrix. We will use an ortho cube centered at (0,0,0) with 100 units of edge*/ glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrthox(FixedFromInt(-50), FixedFromInt(50), FixedFromInt(-50), FixedFromInt(50), FixedFromInt(-50), FixedFromInt(50)); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); return TRUE; }