Commit 4685d45b by Kai Westerkamp

shader start

parent 53b97ddc
......@@ -176,6 +176,8 @@ void Controler::addVolume(QString filePath){
int count = 0;
// std::cout<<std::hex;
int printLine = 150;
for(int k = 0; k < z; k++)
{
data[k] = new char*[y];
......@@ -186,14 +188,13 @@ void Controler::addVolume(QString filePath){
for(int i = 0; i < x; i++)
{
data[k][j][i] = rawdata.at(count++);
if(k == 150 ){
if(k == printLine ){
int temp = ((uchar)data[k][j][i])*9/256;
std::cout<<temp;
// std::cout<<((uint)data[k][j][i]);
}
}
if(k == 150){
//std::cout<<std::endl;
if(k == printLine){
std::cout<<std::endl;
}
}
}
......
......@@ -110,6 +110,9 @@ void GLView::paintGL ()
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_3D,texture3D);
displayShader->setUniformValue("volumeData",0);
shader->setUniformValue("shaded",true);
......
......@@ -290,9 +290,10 @@ MainWindow::MainWindow(QWidget *parent)
//Assemble Tool Bar
initToolbar();
scene->simpleScene();
//controler->addVolume("D:/Projekte/GraPa/A3/lobster.raw");
timer= new QTimer(this);
connect(timer, SIGNAL(timeout()),this,SLOT(initScene()));
timer->start(1000);
setStatusBar(statusBar);
initDoc();
......@@ -300,6 +301,13 @@ MainWindow::MainWindow(QWidget *parent)
}
void MainWindow::initScene(){
//scene->simpleScene();
controler->addVolume("D:/Projekte/GraPa/A3/lobster.raw");
timer->stop();
}
void MainWindow::initDoc()
{
......
......@@ -77,6 +77,8 @@ private:
QSpinBox* gridStepInput;
QToolButton* showGridButton;
QTimer *timer;
void initDoc();
......@@ -104,6 +106,7 @@ public slots:
void showSingle();
void showDual();
void showQuad();
void initScene();
};
#endif // MAINWINDOW_H
uniform bool shaded;
uniform bool volume;
uniform sampler3D volumeData;
varying vec4 pick;
varying vec3 position;
......@@ -7,6 +10,16 @@ varying vec3 normal;
void main(void)
{
vec3 V = normalize(-position);
if(volume){
// gl_FragData[0] = vec4(gl_TexCoord[0].xyz,1);
gl_FragData[0] = vec4(texture3D(volumeData,gl_TexCoord[0].xyz).x);
}
else if(shaded){
vec3 N = normalize(normal);
vec3 L = normalize(gl_LightSource[0].position.xyz-position);
......@@ -16,8 +29,6 @@ void main(void)
vec4 Idiff = gl_FrontLightProduct[0].diffuse*diffuse;
Idiff = clamp(Idiff, 0.0, 1.0);
vec3 V = normalize(-position);
vec3 R = normalize(reflect(-L,N));
......@@ -25,17 +36,13 @@ void main(void)
vec4 Ispec = gl_FrontLightProduct[0].specular * specular;
Ispec = clamp(Ispec, 0.0, 1.0);
vec4 color = (
Iamb
+ Idiff
+ Ispec
);
vec4 color = (Iamb + Idiff + Ispec );
if(shaded)
gl_FragData[0] = color;
}
else
gl_FragData[0] = vec4(1,1,0,1);
gl_FragData[1] = pick;
gl_FragData[1] = vec4(abs(normal),1);
//gl_FragData[1] = vec4(abs(normal),1);
}
......@@ -12,6 +12,7 @@ varying vec3 position;
varying vec3 normal;
varying vec4 pick;
void main(void)
{
normal = normalize(gl_NormalMatrix * gl_Normal);
......@@ -20,6 +21,8 @@ void main(void)
pick = vec4(pickID);
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
}
......@@ -17,6 +17,7 @@ Scene::~Scene( )
int Scene::simpleScene()
{
/*
addCube();
moveActive(QVector3D(4,0,0));
......@@ -33,7 +34,7 @@ int Scene::simpleScene()
addCone();
moveActive(QVector3D(0,-1.5,-1.5));
*/
return active->getID();
......
......@@ -35,23 +35,12 @@ void SceneVolume::draw(QGLShaderProgram *shader){
glPushMatrix();
applyTransformation();
float color[] = {0.0,1.0,1.0};
glMaterialfv(GL_FRONT,GL_AMBIENT,color);
GLfloat white[] = {1.0,1.0,1.0};
glMaterialfv(GL_FRONT,GL_DIFFUSE,color);
glMaterialfv(GL_FRONT,GL_SPECULAR,white);
GLfloat mShininess[] = {128};
glMaterialfv(GL_FRONT,GL_SHININESS,mShininess);
shader->setUniformValue("volume", true);
float x = lx/2;
float y = ly/2;
float z = lz/2;
glBegin(GL_QUADS);
glNormal3f(0,1,0);
glTexCoord3i(1,1,0);
......@@ -124,9 +113,9 @@ void SceneVolume::draw(QGLShaderProgram *shader){
glVertex3f( x, -y, -z);
glEnd();
glPopMatrix();
shader->setUniformValue("volume", false);
}
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