1

i have coded what i have read in previous post about a well known subject but i continue to get a green window without any triangle inside. Here is my paint function :

void mGLWidget::paintGL()
{

glClearColor( Qt::green );

QSize viewport_size = size();
glViewport(0, 0, viewport_size.width(), viewport_size.height());
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1, 1, -1, 1, 5, 7); // near and far match your triangle Z distance
glMatrixMode(GL_MODELVIEW);


glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
glColor4f( 1.0, 1.0, 1.0, 1.0 );

glTranslatef(-1.5f,0.0f,-15.0f);

glBegin(GL_TRIANGLES);         // Drawing Using Triangles
glVertex3f( 0.0f, 1.0f, 0.0f);      // Top
glVertex3f(-1.0f,-1.0f, 0.0f);      // Bottom Left
glVertex3f( 1.0f,-1.0f, 0.0f);      // Bottom Right
glEnd();
// Finished Drawing The Triangle
// swapBuffers();
}

I only get a green window without any triangle. My QT is qt4.8 and opengl 4.0.

What am I doing wrong ?-\

genpfault
  • 51,148
  • 11
  • 85
  • 139
gwen
  • 11
  • 1

2 Answers2

0

your near and far value for your glfrustrum is quite a small range, make it 1, 100 instead of 5, 7. might not be the actual solution but it will help if its not

Fonix
  • 11,447
  • 3
  • 45
  • 74
0

Your near and far value is small and you are translating the triangle very far by -15f unit that means your triangle is not draw or act as a point. So you only see the window color.

Dinesh Subedi
  • 2,603
  • 1
  • 26
  • 36
  • ok. I put glFrustum(-1, 1, -1, 1, 1, 100); and now it works well :) however i don't understand how to choose these values (fot gltranslate and glfrustrus) to be sure to display my whole tesselation. Is there a rule ? i have looked at [link](http://raphaello.univ-fcomte.fr/ig/opengl/opengl-2.htm) but it's still not very clear ... – gwen Jan 29 '13 at 13:55
  • It's like a representation of our eye, how much nearer object we can see and how much far. We can't see object front of near value and behind the far value. So choose considering these things how much value you need. – Dinesh Subedi Jan 29 '13 at 14:18