PDA

View Full Version : OpenGL



igoreshka3333
4th January 2015, 16:36
Hello! I have such a problem: program should display on widget few triangles, which have same vertex. But program display only a vertex))) Can you help me?

Scene.h


#ifndef SCENE_H
#define SCENE_H

#include <QOpenGLWidget>
#include <QKeyEvent>

class Scene : public QOpenGLWidget
{

public:
Scene( QWidget *parent = 0 );

private:
void initializeGL();
void paintGL();
void resizeGL( int w, int h );


};

#endif // SCENE_H

Scene.cpp


#include "scene.h"
#include <math.h>

#define GL_PI 3.1415f

Scene::Scene ( QWidget *parent ) :
QOpenGLWidget ( parent )
{

}

void Scene::initializeGL()
{
glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
glColor3f( 0.0f, 1.0f, 0.0f );
glShadeModel( GL_FLAT );
glFrontFace( GL_CW );

}

void Scene::paintGL()
{
GLfloat angle, x, y;

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glBegin( GL_TRIANGLE_FAN );
glVertex3f( 0.0f, 0.0f, 75.0f );
for( angle = 0.0f; angle < ( 2.0f*GL_PI ); angle += ( GL_PI/8.f ) ){
x = 50.0f*sin( angle );
y = 50.0f*cos( angle );

glVertex2f( x, y );
}
glEnd();
glFlush();
}

void Scene::resizeGL(int w, int h)
{
glViewport( 0, 0, w, h );
glOrtho( -100.0f, 100.0f, -100.0f, 100.0f, 100.0f, -100.0f );

}