mirror of
https://github.com/ConjureETS/LOG750-LAB2.git
synced 2026-03-24 11:31:20 +00:00
wtf
This commit is contained in:
parent
d1ed0a00dd
commit
89c2187f7f
@ -2,6 +2,7 @@
|
|||||||
uniform vec3 lDirection;
|
uniform vec3 lDirection;
|
||||||
uniform bool isSky;
|
uniform bool isSky;
|
||||||
uniform bool isPhong;
|
uniform bool isPhong;
|
||||||
|
uniform bool isPickerColor;
|
||||||
uniform sampler2D tex;
|
uniform sampler2D tex;
|
||||||
uniform float skyMult;
|
uniform float skyMult;
|
||||||
|
|
||||||
@ -16,7 +17,10 @@ void
|
|||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
vec4 texColor = texture(tex, texCoords);
|
vec4 texColor = texture(tex, texCoords);
|
||||||
if(isSky) {
|
|
||||||
|
if(isPickerColor){
|
||||||
|
fColor = ifColor;
|
||||||
|
} else if(isSky) {
|
||||||
fColor = skyMult * normalize(texColor*texColor*texColor*2/1.41)*2;
|
fColor = skyMult * normalize(texColor*texColor*texColor*2/1.41)*2;
|
||||||
} else if(isPhong) {
|
} else if(isPhong) {
|
||||||
// Get lighting vectors
|
// Get lighting vectors
|
||||||
@ -40,5 +44,5 @@ main()
|
|||||||
//fColor = vec4(fNormal, 1);
|
//fColor = vec4(fNormal, 1);
|
||||||
} else {
|
} else {
|
||||||
fColor = texColor * ifColor;
|
fColor = texColor * ifColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,7 @@ uniform vec4 color;
|
|||||||
|
|
||||||
uniform bool isSky;
|
uniform bool isSky;
|
||||||
uniform bool isPhong;
|
uniform bool isPhong;
|
||||||
|
uniform bool isPickerColor;
|
||||||
|
|
||||||
in vec4 vPosition;
|
in vec4 vPosition;
|
||||||
in vec3 vNormal;
|
in vec3 vNormal;
|
||||||
@ -30,7 +31,7 @@ main()
|
|||||||
|
|
||||||
ifColor = color;
|
ifColor = color;
|
||||||
|
|
||||||
if(!isPhong && !isSky) {
|
if(!isPickerColor && !isPhong && !isSky) {
|
||||||
// Get lighting vectors
|
// Get lighting vectors
|
||||||
vec3 LightDirection = normalize(lDirection);
|
vec3 LightDirection = normalize(lDirection);
|
||||||
vec3 nfNormal = normalize(fNormal);
|
vec3 nfNormal = normalize(fNormal);
|
||||||
@ -50,5 +51,6 @@ main()
|
|||||||
ifColor = vec4(color * (0.1 + diffuse + specular), 1);
|
ifColor = vec4(color * (0.1 + diffuse + specular), 1);
|
||||||
//ifColor = vec4(fNormal, 1);
|
//ifColor = vec4(fNormal, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@ in vec4 vPosition;
|
|||||||
void
|
void
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
gl_Position = projMatrix * mvMatrix * vPosition;
|
gl_Position = projMatrix * mvMatrix * vPosition;
|
||||||
texCoords = vUv;
|
texCoords = vUv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,15 +0,0 @@
|
|||||||
#version 400 core
|
|
||||||
|
|
||||||
uniform mat4 mvMatrix;
|
|
||||||
uniform mat4 projMatrix;
|
|
||||||
out vec2 texCoords;
|
|
||||||
in vec2 vUv;
|
|
||||||
in vec4 vPosition;
|
|
||||||
|
|
||||||
void
|
|
||||||
main()
|
|
||||||
{
|
|
||||||
gl_Position = projMatrix * mvMatrix * vPosition;
|
|
||||||
texCoords = vUv;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -300,10 +300,13 @@ void Viewer::initShaders()
|
|||||||
qDebug() << "Unable to find m_shader location for" << "isPhong";
|
qDebug() << "Unable to find m_shader location for" << "isPhong";
|
||||||
|
|
||||||
if ((m_lDirLoc = m_program->uniformLocation("lDirection")) < 0)
|
if ((m_lDirLoc = m_program->uniformLocation("lDirection")) < 0)
|
||||||
qDebug() << "Unable to find m_shader location for" << "lDirection";
|
qDebug() << "Unable to find m_shader location for" << "lDirection";
|
||||||
|
|
||||||
if ((m_skyMultLoc = m_program->uniformLocation("skyMult")) < 0)
|
if ((m_skyMultLoc = m_program->uniformLocation("skyMult")) < 0)
|
||||||
qDebug() << "Unable to find m_shader location for" << "skyMult";
|
qDebug() << "Unable to find m_shader location for" << "skyMult";
|
||||||
|
|
||||||
|
if ((m_pickerColor = m_program->uniformLocation("isPickerColor")) < 0)
|
||||||
|
qDebug() << "Unable to find m_shader location for" << "isPickerColor";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -367,9 +370,9 @@ void Viewer::initGeometries()
|
|||||||
{
|
{
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
glEnable( GL_BLEND );
|
glEnable( GL_BLEND );
|
||||||
//glEnable( GL_CULL_FACE );
|
//glEnable( GL_CULL_FACE );
|
||||||
glFrontFace( GL_CCW );
|
glFrontFace( GL_CCW );
|
||||||
//glCullFace( GL_BACK );
|
//glCullFace( GL_BACK );
|
||||||
glClearColor(0.0,0.0,0.0,0.0);
|
glClearColor(0.0,0.0,0.0,0.0);
|
||||||
|
|
||||||
// Create our VertexArrays Objects and VertexBuffer Objects
|
// Create our VertexArrays Objects and VertexBuffer Objects
|
||||||
@ -478,8 +481,9 @@ void Viewer::visit(Cube &s)
|
|||||||
int faces = floor(numVerticesCube/6);
|
int faces = floor(numVerticesCube/6);
|
||||||
for(int i = 0; i < faces; i++){ // 6 vertexes par face
|
for(int i = 0; i < faces; i++){ // 6 vertexes par face
|
||||||
glBindVertexArray(m_VAOs[VAO_Cube]);
|
glBindVertexArray(m_VAOs[VAO_Cube]);
|
||||||
m_program->setUniformValue(m_isSkyLoc, false);
|
m_program->setUniformValue(m_isSkyLoc, false);
|
||||||
m_program->setUniformValue(m_isPhongLoc, true);
|
m_program->setUniformValue(m_isPhongLoc, true);
|
||||||
|
m_program->setUniformValue(m_pickerColor, true);
|
||||||
m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix);
|
m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix);
|
||||||
m_program->setUniformValue(m_normalMatrixLoc, modelViewMatrix.normalMatrix());
|
m_program->setUniformValue(m_normalMatrixLoc, modelViewMatrix.normalMatrix());
|
||||||
m_program->setUniformValue(m_colorLocation, s.getColor());
|
m_program->setUniformValue(m_colorLocation, s.getColor());
|
||||||
@ -532,9 +536,8 @@ Shape* Viewer::pickGeom(int x, int y){
|
|||||||
* Right now it's fine because we have simple Minecraft rules
|
* Right now it's fine because we have simple Minecraft rules
|
||||||
* but could be important in the future
|
* but could be important in the future
|
||||||
*/
|
*/
|
||||||
QOpenGLShaderProgram *lastshader = m_program;
|
|
||||||
|
|
||||||
//colorPickerShaderProgram->bind();
|
m_program->setUniformValue(m_pickerColor, true);
|
||||||
|
|
||||||
std::cout << "Iterating through " << root.getChildren()->size() << "items"<<endl;
|
std::cout << "Iterating through " << root.getChildren()->size() << "items"<<endl;
|
||||||
|
|
||||||
@ -559,21 +562,22 @@ Shape* Viewer::pickGeom(int x, int y){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
root.accept(*this);
|
||||||
update();
|
update();
|
||||||
|
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||||
|
|
||||||
// for debugging purposes
|
// for debugging purposes
|
||||||
/*QImage *im = new QImage(128,128, QImage::Format_RGB32);
|
/*QImage *im = new QImage(128,128, QImage::Format_RGB32);
|
||||||
for(int i = 0; i< 128; i++){
|
for(int i = 0; i< 128; i++){
|
||||||
for(int j = 0; j< 128; j++){
|
for(int j = 0; j< 128; j++){
|
||||||
glReadPixels(x-64+i, y+64-j, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
|
glReadPixels(x-64+i, y+64-j, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
|
||||||
QColor* pickedColor = new QColor(pixelData[0], pixelData[1], pixelData[2]);
|
QColor* pickedColor = new QColor(pixelData[0], pixelData[1], pixelData[2]);
|
||||||
if(i==64&&j==64) pickedColor->setRgba(0xFFFFFFFF);
|
if(i==64&&j==64) pickedColor->setRgba(0xFFFFFFFF);
|
||||||
im->setPixelColor(i, j, pickedColor->rgb());
|
im->setPixelColor(i, j, pickedColor->rgb());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
im->save("./screenshot.bmp");//*/
|
im->save("./screenshot.bmp");//*/
|
||||||
|
|
||||||
glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
|
glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
|
||||||
QColor* pickedColor = new QColor(pixelData[0], pixelData[1], pixelData[2]);
|
QColor* pickedColor = new QColor(pixelData[0], pixelData[1], pixelData[2]);
|
||||||
@ -582,8 +586,5 @@ Shape* Viewer::pickGeom(int x, int y){
|
|||||||
std::cout << "Picked Color: " << pickedColor->red() << " " << pickedColor->green() << " " << pickedColor->blue() << " " << pickedColor->alpha() << endl;
|
std::cout << "Picked Color: " << pickedColor->red() << " " << pickedColor->green() << " " << pickedColor->blue() << " " << pickedColor->alpha() << endl;
|
||||||
std::cout << "Picked Shape: " << pickedShape << endl;
|
std::cout << "Picked Shape: " << pickedShape << endl;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//lastshader->bind();
|
|
||||||
return pickedShape;
|
return pickedShape;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -97,7 +97,8 @@ private:
|
|||||||
int m_isPhongLoc;
|
int m_isPhongLoc;
|
||||||
int m_isSkyLoc;
|
int m_isSkyLoc;
|
||||||
int m_lDirLoc;
|
int m_lDirLoc;
|
||||||
int m_skyMultLoc;
|
int m_skyMultLoc;
|
||||||
|
bool m_pickerColor;
|
||||||
|
|
||||||
float angle_mult;
|
float angle_mult;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user