Sometimes, render some strange triangles

Hey everyone,

Im rendering a scene in the OpenGL ES, and sometimes appear new strange triangles in the scene.

Im navigating in the scene changing the position of the gluLookAt.

In the image, im navigating…
Frame 2 the LookAt is - 2f in z from Frame 1
Frame 3 the LookAt is - 2f in z from Frame 2
Frame 4 the LookAt is - 2f in z from Frame 3
But, in the frame 4 the render get messed

http://img231.imageshack.us/img231/9739/frameskr2.jpg

  • the model is correct. I have this model perfect rendered in Java3D

Thank you

Wendel B Silva

theres a video on youtube, you can see the problem

I think is something related with the camera.

Im changing the lookat parameters to simulate the navigation through the scene.

Any idea?

-[ edit ]=-=-=-=-=-=-
i though was the lookAt, but using the Fadi’s(1) implemention of the lookat, the program still have the same problem

(1) - http://www.khronos.org/message_boards/v … .php?t=541

Please post some code. Also, which OpenGL ES implementation are you using?

Im using Vincent Implementation… i tried use Rasteroid but i get the same problem

The variable Vertex im allocating and getting the vertex at runtime.
The normal im calculating and normalizing the calculated values.

#pragma comment(lib, "libGLES_CM.lib")

#define GLUTES_STATIC

#include <GLES/glutes.h>
#include <GLES/glues.h>
#include <GLES/glues.c>
#include "main.h"

//CONST
const GLfloat PI = 3.14159265f;
const int TAM = 60;

int             	VerticeCount = 0;		//Vertex count of the scene
GLfloat*		Vertex;				//VerticeCount*3
GLfloat*		Normal;				

int   regiaoAtual[] = {-1, -1, -1};
GLfloat xrot = 0;
GLfloat yrot = 0.0f;
GLfloat transx = 0.0f;
GLfloat transy = 0.0f;
GLfloat transz = 0.0f;

bool backFace = true;
char* windowCaption = "Wendel - OpenGL ES ";

void init()
{
/*-=-=-=-=-=-=-=[ Lights ]=-=-=-=-=-=-*/
	GLfloat matAmbient[] = { 0.6f, 0.6f, 0.6f, 1.0f };
	GLfloat matDiffuse[] = { 0.8f, 0.4f, 0.4f, 1.0f };
	GLfloat lightAmbient[] = { 0.8f, 0.6f, 0.6f, 1.0f };
	GLfloat lightDiffuse[] = { 0.6f, 0.3f, 0.3f, 1.0f };

	//SPOT LIGHT
	GLfloat lightPos1[]= { 20.0, 20.0, 20.0,1.0};
	GLfloat lightPos2[]= {-20.0, 20.0, 20.0,1.0};
	GLfloat lightPos3[]= { 20.0, 20.0,-20.0,1.0};
	GLfloat lightPos4[]= {-20.0, 20.0,-20.0,1.0};
	GLfloat spotDir1[]= {-0.5f,-0.5f,-0.5f};
	GLfloat spotDir2[]= { 0.5f,-0.5f,-0.5f};
	GLfloat spotDir3[]= {-0.5f,-0.5f, 0.5f};
	GLfloat spotDir4[]= { 0.5f,-0.5f, 0.5f};

    glLightfv(GL_LIGHT0, GL_AMBIENT , lightAmbient);
	glLightfv(GL_LIGHT0, GL_DIFFUSE , lightDiffuse);

	glLightfv(GL_LIGHT1, GL_DIFFUSE , lightDiffuse);
	glLightfv(GL_LIGHT1, GL_AMBIENT , lightAmbient);
	glLightfv(GL_LIGHT1, GL_POSITION, lightPos1);
	glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, spotDir1);
	glLightf (GL_LIGHT1, GL_SPOT_CUTOFF,  40.0);    	// set cutoff angle
	glLightf (GL_LIGHT1, GL_SPOT_EXPONENT, 30.0);   	// set focusing strength

	glLightfv(GL_LIGHT1, GL_DIFFUSE , lightDiffuse);
	glLightfv(GL_LIGHT1, GL_AMBIENT , lightAmbient);
	glLightfv(GL_LIGHT1, GL_POSITION, lightPos2);
	glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, spotDir2);
	glLightf (GL_LIGHT1, GL_SPOT_CUTOFF,  40.0);    	// set cutoff angle
	glLightf (GL_LIGHT1, GL_SPOT_EXPONENT, 30.0);   	// set focusing strength

	glLightfv(GL_LIGHT1, GL_DIFFUSE , lightDiffuse);
	glLightfv(GL_LIGHT1, GL_AMBIENT , lightAmbient);
	glLightfv(GL_LIGHT1, GL_POSITION, lightPos3);
	glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, spotDir3);
	glLightf (GL_LIGHT1, GL_SPOT_CUTOFF,  40.0);    	// set cutoff angle
	glLightf (GL_LIGHT1, GL_SPOT_EXPONENT, 30.0);   	// set focusing strength

	glLightfv(GL_LIGHT1, GL_DIFFUSE , lightDiffuse);
	glLightfv(GL_LIGHT1, GL_AMBIENT , lightAmbient);
	glLightfv(GL_LIGHT1, GL_POSITION, lightPos4);
	glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, spotDir4);
	glLightf (GL_LIGHT1, GL_SPOT_CUTOFF,  40.0);    	// set cutoff angle
	glLightf (GL_LIGHT1, GL_SPOT_EXPONENT, 30.0);   	// set focusing strength

	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, matAmbient);
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, matDiffuse);
	glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, 20.0f);

	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glEnable(GL_LIGHT1);
	glEnable(GL_LIGHT2);
	glEnable(GL_LIGHT3);

/*-=-=-=-=-=-=-=[ init  ]=-=-=-=-=-=-*/
	timePrev = GetTickCount();

	glDepthFunc(GL_LEQUAL);

	glShadeModel(GL_SMOOTH);
	
	glEnable(GL_DEPTH_TEST);
	if (backFace){ glCullFace(GL_BACK); glEnable(GL_CULL_FACE); }

//	Clear	
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClearDepthf(1.0f);

	glVertexPointer(3, GL_FLOAT, 0, Vertex);	
	glNormalPointer(GL_FLOAT, 0, Normal);
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_NORMAL_ARRAY);
}


void display()
{
//	Clear
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClearDepthf(1.0f);
	glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);

//	rotation
	GLfloat dx = (GLfloat)sin(yrot*PI/180.0f);
	GLfloat dz = (GLfloat)cos(yrot*PI/180.0f);
	GLfloat dy = (GLfloat)sin(xrot*PI/180.0f);
	GLfloat dz2= (GLfloat)cos(xrot*PI/180.0f);

//	Camera
	glLoadIdentity();
	gluLookAtf(
		transx    , transy   , transz,				//Eye    
		transx-dx , transy+dy, transz-dz-dz2+1.0f,		//Center 
		0.0f      , 1.0f, 0.0f  );					//Up     
   
//	draw
	glDrawArrays(GL_TRIANGLES, 0, VerticeCount);	

	glFlush();
	glutSwapBuffers();	
}

void idle()
{
	glutPostRedisplay();
}

void special(int key, int x, int y)
{
	GLfloat passo = 0.5f;
	GLfloat rotacao = 10;
	GLfloat dx = (GLfloat)sin(yrot*PI/180.0);
	GLfloat dz = (GLfloat)cos(yrot*PI/180.0);

	switch(key)
	{

	case GLUT_KEY_F1	: yrot += rotacao; break;
	case GLUT_KEY_F2	: yrot -= rotacao; break;
	case GLUT_KEY_HOME	: transy += passo; break;
	case GLUT_KEY_END	: transy -= passo; break;

	case GLUT_KEY_LEFT  : 
		transx -= passo*dz;
		transz += passo*dx;
		break;
	case GLUT_KEY_RIGHT : 
		transx += passo*dz;
		transz -= passo*dx;
		break;

	case GLUT_KEY_UP    : 
		transz -= dz*passo; 
		transx -= dx*passo; 
		break;
	case GLUT_KEY_DOWN  : 
		transz += dz*passo; 
		transx += dx*passo; 
		break;
	}
	glutPostRedisplay();
}

void reshape(int width, int height)
{
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	if (!height)
		height = 1;

	glViewport(0, 0, width, height);
	gluPerspectivef(45.0f, 1.0f * width / height, 1.0f, 100.0f);

	glMatrixMode(GL_MODELVIEW);	
	glLoadIdentity();
}

void freememory(){
	delete[] Vertex;
	delete[] Normal;
}

int main(int argc, char *argv[])
{		
			
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_MULTISAMPLE);
	glutCreateWindow(windowCaption);

	init();

	glutDisplayFunc(display);
	glutReshapeFunc(reshape);
	glutSpecialFunc(special);

	glutIdleFunc(idle);

	glutCreateMenu(menu);
	glutAddMenuEntry("Quit", 1);
	glutAttachMenu(GLUT_LEFT_BUTTON);

	glutMainLoop();

	freememory();

	return 0;
}

void menu(int entry)
{
	switch(entry)
	{
	case 1 : exit(0); break;
	}
}

I updated the code above to almost everything i have in the main.c.

Any idea how can i solve this problem?

thank you

*ps: sorry for the flood… im updating this topic because i really need fix this

Running the example 13 of the Zeus Tutorial, i have the same problem.

I got the example 13 of Zeus Tutorial, make 1 addition

  • Move the LookAt in -Z and +Y

When the LookAt is right above the box, the same problem appear… dont matter the Y.


//13 - SolidShapes
//From the example 13, was changed... 
//keyboard2 to \/
void keyboard2(int key, int x, int y)
{
	switch(key)
	{
	case GLUT_KEY_UP    : zz-=1; break;
	case GLUT_KEY_DOWN  : zz+=1; break;
	case GLUT_KEY_LEFT  : xx-=1; break;
	case GLUT_KEY_RIGHT : xx+=1; break;
	case GLUT_KEY_HOME  : yy+=1; break;
	case GLUT_KEY_END   : yy-=1; break;
	}
}
//and gluLookAtf to \/
   gluLookAtf(
		0.0f+xx, 0.0f+yy, 3.0f+zz,
		0.0f+xx, 0.0f+yy, 0.0f+zz,
		0.0f, 1.0f, 0.0f);

Link to the tutorial example

Im using EVC4 and Vincent… and GLUT|ES
No geometry was show when i tried run with Hybrid Rasteroid

It’s strange that mutliple implementations and even the Zeus examples don’t work. How about trying to debug this in a desktop environment, for example using http://developer.hybrid.fi/dgles/index.html?

For Vincent, your model looks gigantic, so I wouldn’t be surprised if you end up getting overflow/underflow problems; after all, it’s only a fixed-point implementation.

  • HM

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.