Commit 0de3f161 by Kai Westerkamp

grid

parent 78f61664
......@@ -7,6 +7,9 @@ GLView::GLView(Scene *scene,Camera * camera,Controler *controler )
this->camera = camera;
this->scene = scene;
this->controler = controler;
gridSize = 5;
gridStepSize = 1;
isGridEnabled = true;
}
QSize GLView::minimumSizeHint() const
......@@ -103,6 +106,12 @@ void GLView::paintGL ()
//draw Scene
scene->draw();
if(isGridEnabled){
drawGrid();
}
if(isActive){
glDisable(GL_DEPTH_TEST);
glMatrixMode (GL_MODELVIEW);
......@@ -126,6 +135,7 @@ void GLView::paintGL ()
}
shader->release();
// displayShader->bind();
// functions.glBindFramebuffer(GL_FRAMEBUFFER,fbo);
......@@ -147,9 +157,106 @@ void GLView::paintGL ()
// displayShader->release();
}
void GLView::drawGrid()
{
shader->release();
GLfloat specularColor[] = {0,0,0};
GLfloat shininess[] = {128};
glMaterialfv(GL_FRONT,GL_SPECULAR,specularColor);
glMaterialfv(GL_FRONT,GL_SHININESS, shininess);
GLfloat grey[] = {1,0.5,0.5};
glMaterialfv(GL_FRONT,GL_DIFFUSE,grey);
glNormal3f(0,1,0);
glDisable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
glLineWidth(1);
glPolygonMode(GL_FRONT_AND_BACK,GL_LINES);
glBegin(GL_LINES);
float stepSize = gridStepSize;
float x = stepSize;
float y = stepSize;
if (stepSize <= 0) stepSize = 1;
for(; x < gridSize; x += stepSize){
glVertex3f(x,0,-gridSize);
glVertex3f(x,0,gridSize);
glVertex3f(-x,0,-gridSize);
glVertex3f(-x,0,gridSize);
}
for (; y < gridSize; y += stepSize){
glVertex3f(-gridSize, 0, y);
glVertex3f(gridSize,0,y);
glVertex3f(-gridSize,0,-y);
glVertex3f(gridSize,0,-y);
}
glEnd();
glBegin(GL_LINES);
x = stepSize;
y = stepSize;
if (stepSize <= 0) stepSize = 1;
for(; x < gridSize; x += stepSize){
glVertex3f(0,x,-gridSize);
glVertex3f(0,x,gridSize);
glVertex3f(0,-x,-gridSize);
glVertex3f(0,-x,gridSize);
}
for (; y < gridSize; y += stepSize){
glVertex3f(0,-gridSize, y);
glVertex3f(0,gridSize,y);
glVertex3f(0,-gridSize,-y);
glVertex3f(0,gridSize,-y);
}
glEnd();
glBegin(GL_LINES);
x = stepSize;
y = stepSize;
if (stepSize <= 0) stepSize = 1;
for(; x < gridSize; x += stepSize){
glVertex3f(x,-gridSize,0);
glVertex3f(x,gridSize,0);
glVertex3f(-x,-gridSize,0);
glVertex3f(-x,gridSize,0);
}
for (; y < gridSize; y += stepSize){
glVertex3f(-gridSize, y,0);
glVertex3f(gridSize,y,0);
glVertex3f(-gridSize,-y,0);
glVertex3f(gridSize,-y,0);
}
glEnd();
glBegin(GL_LINES);
glVertex3f(0,0,-gridSize);
glVertex3f(0,0,gridSize);
glEnd();
glBegin(GL_LINES);
glVertex3f(-gridSize,0,0);
glVertex3f(gridSize,0,0);
glEnd();
glBegin(GL_LINES);
glVertex3f(0,-gridSize,0);
glVertex3f(0,gridSize,0);
glEnd();
glPolygonMode(GL_FRONT,GL_FILL);
glEnable(GL_LIGHTING);
shader->bind();
}
void GLView::resizeGL(int width , int height )
{
aspect = 1.0*width/height;
......
......@@ -51,8 +51,12 @@ private:
GLuint picID;
GLuint depth;
void drawGrid();
void initShader();
float gridStepSize;
float gridSize;
bool isGridEnabled;
};
#endif // GLVIEW_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment