Hi everyone.
I’m having some strange problems using Vincent 3D library 1.0 with windows mobile emulator. I have tried both Windows mobile 6 and pocket pc 2003 emulator.
The problem occur using perspective projection. When the camera is between the z-near and the z-far coordinates (where z is my depth axis) of a 3D solid, strange transformations occur.
The best way to explain is to show you a video: - YouTube
The cube has x coordinate equal to -4.0, the camera does not pass thorugh it.
I tried the same animation on several code examples and i always got the same result. Also using UG lib instead of GLUT|ES same problem occurs
Where’s the problem? Is is a library bug?!!
Here the relevant OpenGL code:
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(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;
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);
glClearColor(255, 255, 255, 0);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
RECT r;
GetWindowRect(hWnd, &r);
glViewport(r.left, r.top, r.right - r.left, r.bottom - r.top);
float ratio = (float)(r.right - r.left)/(r.bottom - r.top);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspectivef(45.0f, ratio, 0.1f, 1000.0f);
glMatrixMode(GL_MODELVIEW);
glEnableClientState(GL_VERTEX_ARRAY);
printf("Rendering...
");
return true;
}
void render()
{
static GLubyte front[] = {2,1,3,0}; //front face
static GLubyte back[] = {5,6,4,7}; //back face
static GLubyte top[] = {6,2,7,3}; //top face
static GLubyte bottom[] = {1,5,0,4}; //bottom face
static GLubyte left[] = {3,0,7,4}; //left face
static GLubyte right[] = {6,5,2,1}; //right face
static GLshort vertices[] = {-1,-1,-1, 1,-1,-1, 1,1,-1, -1,1,-1,
-1,-1,1, 1,-1,1, 1,1,1, -1,1,1};
static GLfloat k = -20;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAtf( 0,0,0,
0,0,-1,
0, 1, 0
);
glTranslatef(-4,0,k);
k += 0.1;
glVertexPointer(3, GL_SHORT, 0, vertices);
/*We are going to draw the cube, face by face, with different colors for
each face, using indexed vertex arrays and triangle strips*/
glColor4f(1,0,0,0);
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, front);
glColor4f(0,1,0,0);
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, back);
glColor4f(0,0,1,0);
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, top);
glColor4f(1,1,0,0);
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, bottom);
glColor4f(0,1,1,0);
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, left);
glColor4f(1,0,1,0);
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, right);
eglSwapBuffers(glesDisplay, glesSurface);
}