#define GL_GLEXT_PROTOTYPE
#include "glwidget.h"
#include<GL/glut.h>
#include "structs_and_classes.h"
#include<iostream>
extern float* vertices;
extern std::vector<triangle> facet;
int NUM_VERTICES= 3*facet.size();
GLWidget::GLWidget(QWidget *parent):
QGLWidget(parent)
{
connect(&timer ,SIGNAL(timeout()),this,SLOT(updateGL()));
timer.start((16));
}
void GLWidget::initilaizeGL()
{
initializeGLFunctions(QGLContext::currentContext());
// select background color to be black
float R = 7, G = 54, B = 66, alpha = 255;
qglClearColor(QColor(R,G,B,alpha));
// clear all pixels in the window with the color selected above
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST); // hidden surface removal
glEnable(GL_CULL_FACE);
glShadeModel(GL_SMOOTH);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
static GLfloat lightPosition[4] = { 0, 0, 10, 1.0 };
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
// create a Vertex Buffer Object (VBO) and bind the vertex array to it
// makes rendering faster because data is copied to GPU memory
GLuint bufferID;
QGLFunctions:: glGenBuffers(1, &bufferID);
QGLFunctions:: glBindBuffer(GL_ARRAY_BUFFER, bufferID);
QGLFunctions::glBufferData(GL_ARRAY_BUFFER,facet.size()*30*sizeof(GLfloat),vertices,GL_STATIC_DRAW);
// fill mode or wireframe mode
glPolygonMode(GL_FRONT, // options: GL_FRONT, GL_BACK, GL_FRONT_AND_BACK
GL_FILL); // options: GL_POINT, GL_LINE, GL_FILL (default)
// shading model
glShadeModel(GL_SMOOTH);
void GLWidget::paintGL()
{
//select background color to be black
float R = 7, G = 54, B = 66, alpha = 255;
qglClearColor(QColor(R,G,B,alpha));
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//-----------------------------------------------------------
// Enable use of vertex data (coordinates, normals and color)
//-----------------------------------------------------------
// enable use of vertex coordinate information from the array
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, // number of coordinates per vertex (X,Y,Z)
GL_FLOAT, // type of numbers
sizeof(float)*10, // stride - gap between each set of (X,Y,Z)
(GLvoid*)((char*)NULL)); // offset - location of initial (X,Y,Z)
// enable use of vertex normal information from the array
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, // type of values
sizeof(float)*10, // stride - gap between each set of (N_x,N_y,N_z)
(GLvoid*)(((char*)NULL) + 12)); // offset - location of initial (N_x,N_y,N_z)
// enable use of vertex color information from the array
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(4, // number of color values per vertex (R,G,B,A)
GL_FLOAT, // type of values
sizeof(float)*10, // stride - gap between each set of (R,G,B,A)
(GLvoid*)(((char*)NULL) + 24)); // offset - location of initial (R,G,B,A)
//------------------
// draw the geometry
//------------------
glDrawArrays(GL_TRIANGLES, // type of GL element
0, // starting offset
NUM_VERTICES); // number of vertices to be used for rendering
So, do you have a specific OpenGL question? What have you done to try and figure out what the problem is? This isn’t a debugging service.
You’ll get much better response to your question if you 1) try to fix your own problems and ask specific OpenGL-related questions, and 2) post a stand-alone GLUT test program that folks can compile to see everything you’re doing.