void ParticleRenderer2D::drawParticles( uint32_t count, const glm::vec2* positionArray, const float* massArray, const glm::vec3* colorArray, unsigned int * instrumentArray, int * lifetimeArray, float size, float volume) { // Active la gestion de la transparence glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_DEPTH_TEST); glUseProgram(m_ProgramID); glBindVertexArray(m_VAOID); glm::vec3 bassColor = m_band[Instrument::bass].giveColor(soundManager->scaleVolume(volume)); glm::vec3 drumsColor = m_band[Instrument::drums].giveColor(soundManager->scaleVolume(volume)); glm::vec3 guitarAColor = m_band[Instrument::guitarA].giveColor(soundManager->scaleVolume(volume)); glm::vec3 guitarBColor = m_band[Instrument::guitarB].giveColor(soundManager->scaleVolume(volume)); // Dessine chacune des particules for(uint32_t i = 0; i < count; ++i) { if(soundManager->getMaxVolume() > 0) { // renvoyer la bonne couleur en fonction de l'instrument de la particule //~ glm::vec3 color = Instrument::giveColor(glm::vec3(0.), soundManager->scaleVolume(volume)); glm::vec3 color; float coef = float(lifetimeArray[i]) / 100.f; //~ std::cout << "coef : " << coef << std::endl; switch(instrumentArray[i]){ case Instrument::bass: color = bassColor*coef; break; case Instrument::drums: color = drumsColor*coef; break; case Instrument::guitarA: color = guitarAColor*coef; break; case Instrument::guitarB: color = guitarBColor*coef; break; default: color = glm::vec3(1.)*coef; break; }; glUniform3fv(m_uParticleColor, 1, glm::value_ptr(color)); } else { glUniform3fv(m_uParticleColor, 1, glm::value_ptr(colorArray[i])); } glUniform2fv(m_uParticlePosition, 1, glm::value_ptr(positionArray[i])); glUniform1f(m_uParticleScale, m_fMassScale * size); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } glBindVertexArray(0); glDisable(GL_BLEND); }
/*!**************************************************************************** @Function RenderScene @Return bool true if no error occured @Description Main rendering loop function of the program. The shell will call this function every frame. eglSwapBuffers() will be performed by PVRShell automatically. PVRShell will also manage important OS events. Will also manage relevent OS events. The user has access to these events through an abstraction layer provided by PVRShell. ******************************************************************************/ bool OGLES2ChameleonMan::RenderScene() { // Clear the color and depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Use shader program glUseProgram(m_SkinnedShaderProgram.uiId); if(PVRShellIsKeyPressed(PVRShellKeyNameACTION1)) { m_bEnableDOT3 = !m_bEnableDOT3; glUniform1i(m_SkinnedShaderProgram.auiLoc[ebUseDot3], m_bEnableDOT3); } /* Calculates the frame number to animate in a time-based manner. Uses the shell function PVRShellGetTime() to get the time in milliseconds. */ unsigned long iTime = PVRShellGetTime(); if(iTime > m_iTimePrev) { float fDelta = (float) (iTime - m_iTimePrev); m_fFrame += fDelta * g_fDemoFrameRate; // Increment the counters to make sure our animation works m_fLightPos += fDelta * 0.0034f; m_fWallPos += fDelta * 0.00027f; m_fBackgroundPos += fDelta * -0.000027f; // Wrap the Animation back to the Start if(m_fLightPos >= PVRT_TWO_PI) m_fLightPos -= PVRT_TWO_PI; if(m_fWallPos >= PVRT_TWO_PI) m_fWallPos -= PVRT_TWO_PI; if(m_fBackgroundPos <= 0) m_fBackgroundPos += 1.0f; if(m_fFrame > m_Scene.nNumFrame - 1) m_fFrame = 0; } m_iTimePrev = iTime; // Set the scene animation to the current frame m_Scene.SetFrame(m_fFrame); // Set up camera PVRTVec3 vFrom, vTo, vUp(0.0f, 1.0f, 0.0f); PVRTMat4 mView, mProjection; PVRTVec3 LightPos; float fFOV; int i; bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen); // Get the camera position, target and field of view (fov) if(m_Scene.pCamera[0].nIdxTarget != -1) // Does the camera have a target? fFOV = m_Scene.GetCameraPos( vFrom, vTo, 0); // vTo is taken from the target node else fFOV = m_Scene.GetCamera( vFrom, vTo, vUp, 0); // vTo is calculated from the rotation fFOV *= bRotate ? (float)PVRShellGet(prefWidth)/(float)PVRShellGet(prefHeight) : (float)PVRShellGet(prefHeight)/(float)PVRShellGet(prefWidth); /* We can build the model view matrix from the camera position, target and an up vector. For this we use PVRTMat4::LookAtRH(). */ mView = PVRTMat4::LookAtRH(vFrom, vTo, vUp); // Calculate the projection matrix mProjection = PVRTMat4::PerspectiveFovRH(fFOV, (float)PVRShellGet(prefWidth)/(float)PVRShellGet(prefHeight), g_fCameraNear, g_fCameraFar, PVRTMat4::OGL, bRotate); // Update Light Position and related VGP Program constant LightPos.x = 200.0f; LightPos.y = 350.0f; LightPos.z = 200.0f * PVRTABS(sin((PVRT_PI / 4.0f) + m_fLightPos)); glUniform3fv(m_SkinnedShaderProgram.auiLoc[eLightPos], 1, LightPos.ptr()); // Set up the View * Projection Matrix PVRTMat4 mViewProjection; mViewProjection = mProjection * mView; glUniformMatrix4fv(m_SkinnedShaderProgram.auiLoc[eViewProj], 1, GL_FALSE, mViewProjection.ptr()); // Enable the vertex attribute arrays for(i = 0; i < eNumAttribs; ++i) glEnableVertexAttribArray(i); // Draw skinned meshes for(unsigned int i32NodeIndex = 0; i32NodeIndex < 3; ++i32NodeIndex) { // Bind correct texture switch(i32NodeIndex) { case eBody: glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, m_ui32TexHeadNormalMap); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_ui32TexHeadBody); break; case eLegs: glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, m_ui32TexLegsNormalMap); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_ui32TexLegs); break; default: glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, m_ui32TexBeltNormalMap); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_ui32TexBelt); break; } DrawSkinnedMesh(i32NodeIndex); } // Safely disable the vertex attribute arrays for(i = 0; i < eNumAttribs; ++i) glDisableVertexAttribArray(i); // Draw non-skinned meshes glUseProgram(m_DefaultShaderProgram.uiId); // Enable the vertex attribute arrays for(i = 0; i < eNumDefaultAttribs; ++i) glEnableVertexAttribArray(i); for(unsigned int i32NodeIndex = 3; i32NodeIndex < m_Scene.nNumMeshNode; ++i32NodeIndex) { SPODNode& Node = m_Scene.pNode[i32NodeIndex]; SPODMesh& Mesh = m_Scene.pMesh[Node.nIdx]; // bind the VBO for the mesh glBindBuffer(GL_ARRAY_BUFFER, m_puiVbo[Node.nIdx]); // bind the index buffer, won't hurt if the handle is 0 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_puiIndexVbo[Node.nIdx]); // Get the node model matrix PVRTMat4 mWorld; mWorld = m_Scene.GetWorldMatrix(Node); // Setup the appropriate texture and transformation (if needed) switch(i32NodeIndex) { case eWall: glBindTexture(GL_TEXTURE_2D, m_ui32TexWall); // Rotate the wall mesh which is circular mWorld *= PVRTMat4::RotationY(m_fWallPos); glUniform1f(m_DefaultShaderProgram.auiLoc[eDefaultUOffset], 0); break; case eBackground: glBindTexture(GL_TEXTURE_2D, m_ui32TexSkyLine); glUniform1f(m_DefaultShaderProgram.auiLoc[eDefaultUOffset], m_fBackgroundPos); break; case eLights: { glBindTexture(GL_TEXTURE_2D, m_ui32TexLamp); PVRTMat4 mWallWorld = m_Scene.GetWorldMatrix(m_Scene.pNode[eWall]); mWorld = mWallWorld * PVRTMat4::RotationY(m_fWallPos) * mWallWorld.inverse() * mWorld; glUniform1f(m_DefaultShaderProgram.auiLoc[eDefaultUOffset], 0); } break; default: break; }; // Set up shader uniforms PVRTMat4 mModelViewProj; mModelViewProj = mViewProjection * mWorld; glUniformMatrix4fv(m_DefaultShaderProgram.auiLoc[eDefaultMVPMatrix], 1, GL_FALSE, mModelViewProj.ptr()); // Set the vertex attribute offsets glVertexAttribPointer(DEFAULT_VERTEX_ARRAY, 3, GL_FLOAT, GL_FALSE, Mesh.sVertex.nStride, Mesh.sVertex.pData); glVertexAttribPointer(DEFAULT_TEXCOORD_ARRAY, 2, GL_FLOAT, GL_FALSE, Mesh.psUVW[0].nStride, Mesh.psUVW[0].pData); // Indexed Triangle list glDrawElements(GL_TRIANGLES, Mesh.nNumFaces*3, GL_UNSIGNED_SHORT, 0); } // Safely disable the vertex attribute arrays for(i = 0; i < eNumAttribs; ++i) glDisableVertexAttribArray(i); // unbind the VBOs glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); // Display the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools const char * pDescription; if(m_bEnableDOT3) pDescription = "Skinning with DOT3 Per Pixel Lighting"; else pDescription = "Skinning with Vertex Lighting"; m_Print3D.DisplayDefaultTitle("Chameleon Man", pDescription, ePVRTPrint3DSDKLogo); m_Print3D.Flush(); return true; }
void Program::uniform1f(const char *uniform, float f) { GLuint id = getUniformLocation(uniform); glUniform1f(id, f); }
void ShaderTechnique::setScalef(float f){ glUniform1f(m_uScaleLocation, f); }
void CustomShader::render(const glm::mat4& mvp_matrix, RenderData* render_data, Material* material, bool right) { Mesh* mesh = render_data->mesh(); #if _GVRF_USE_GLES3_ glUseProgram(program_->id()); for (auto it = attribute_float_keys_.begin(); it != attribute_float_keys_.end(); ++it) { mesh->setVertexAttribLocF(it->first, it->second); } for (auto it = attribute_vec2_keys_.begin(); it != attribute_vec2_keys_.end(); ++it) { mesh->setVertexAttribLocV2(it->first, it->second); } for (auto it = attribute_vec3_keys_.begin(); it != attribute_vec3_keys_.end(); ++it) { mesh->setVertexAttribLocV3(it->first, it->second); } for (auto it = attribute_vec4_keys_.begin(); it != attribute_vec4_keys_.end(); ++it) { mesh->setVertexAttribLocV4(it->first, it->second); } mesh->generateVAO(); // setup VAO ///////////// uniform ///////// for (auto it = uniform_float_keys_.begin(); it != uniform_float_keys_.end(); ++it) { glUniform1f(it->first, material->getFloat(it->second)); } if (u_mvp_ != -1) { glUniformMatrix4fv(u_mvp_, 1, GL_FALSE, glm::value_ptr(mvp_matrix)); } if (u_right_ != 0) { glUniform1i(u_right_, right ? 1 : 0); } int texture_index = 0; for (auto it = texture_keys_.begin(); it != texture_keys_.end(); ++it) { glActiveTexture(getGLTexture(texture_index)); Texture* texture = material->getTexture(it->second); glBindTexture(texture->getTarget(), texture->getId()); glUniform1i(it->first, texture_index++); } for (auto it = uniform_vec2_keys_.begin(); it != uniform_vec2_keys_.end(); ++it) { glm::vec2 v = material->getVec2(it->second); glUniform2f(it->first, v.x, v.y); } for (auto it = uniform_vec3_keys_.begin(); it != uniform_vec3_keys_.end(); ++it) { glm::vec3 v = material->getVec3(it->second); glUniform3f(it->first, v.x, v.y, v.z); } for (auto it = uniform_vec4_keys_.begin(); it != uniform_vec4_keys_.end(); ++it) { glm::vec4 v = material->getVec4(it->second); glUniform4f(it->first, v.x, v.y, v.z, v.w); } for (auto it = uniform_mat4_keys_.begin(); it != uniform_mat4_keys_.end(); ++it) { glm::mat4 m = material->getMat4(it->second); glUniformMatrix4fv(it->first, 1, GL_FALSE, glm::value_ptr(m)); } glBindVertexArray(mesh->getVAOId(material->shader_type())); glDrawElements(GL_TRIANGLES, mesh->triangles().size(), GL_UNSIGNED_SHORT, 0); glBindVertexArray(0); #else glUseProgram(program_->id()); if (a_position_ != -1) { glVertexAttribPointer(a_position_, 3, GL_FLOAT, GL_FALSE, 0, mesh->vertices().data()); glEnableVertexAttribArray(a_position_); } if (a_normal_ != -1) { glVertexAttribPointer(a_normal_, 3, GL_FLOAT, GL_FALSE, 0, mesh->normals().data()); glEnableVertexAttribArray(a_normal_); } if (a_tex_coord_ != -1) { glVertexAttribPointer(a_tex_coord_, 2, GL_FLOAT, GL_FALSE, 0, mesh->tex_coords().data()); glEnableVertexAttribArray(a_tex_coord_); } if (u_mvp_ != -1) { glUniformMatrix4fv(u_mvp_, 1, GL_FALSE, glm::value_ptr(mvp_matrix)); } if (u_right_ != 0) { glUniform1i(u_right_, right ? 1 : 0); } int texture_index = 0; for (auto it = texture_keys_.begin(); it != texture_keys_.end(); ++it) { glActiveTexture(getGLTexture(texture_index)); Texture* texture = render_data->material()->getTexture( it->second); glBindTexture(texture->getTarget(), texture->getId()); glUniform1i(it->first, texture_index++); } for (auto it = attribute_float_keys_.begin(); it != attribute_float_keys_.end(); ++it) { glVertexAttribPointer(it->first, 1, GL_FLOAT, GL_FALSE, 0, mesh->getFloatVector(it->second).data()); glEnableVertexAttribArray(it->first); } for (auto it = attribute_vec2_keys_.begin(); it != attribute_vec2_keys_.end(); ++it) { glVertexAttribPointer(it->first, 2, GL_FLOAT, GL_FALSE, 0, mesh->getVec2Vector(it->second).data()); glEnableVertexAttribArray(it->first); } for (auto it = attribute_vec3_keys_.begin(); it != attribute_vec3_keys_.end(); ++it) { glVertexAttribPointer(it->first, 3, GL_FLOAT, GL_FALSE, 0, mesh->getVec3Vector(it->second).data()); glEnableVertexAttribArray(it->first); } for (auto it = attribute_vec4_keys_.begin(); it != attribute_vec4_keys_.end(); ++it) { glVertexAttribPointer(it->first, 4, GL_FLOAT, GL_FALSE, 0, mesh->getVec4Vector(it->second).data()); glEnableVertexAttribArray(it->first); } for (auto it = uniform_float_keys_.begin(); it != uniform_float_keys_.end(); ++it) { glUniform1f(it->first, render_data->material()->getFloat(it->second)); } for (auto it = uniform_vec2_keys_.begin(); it != uniform_vec2_keys_.end(); ++it) { glm::vec2 v = render_data->material()->getVec2(it->second); glUniform2f(it->first, v.x, v.y); } for (auto it = uniform_vec3_keys_.begin(); it != uniform_vec3_keys_.end(); ++it) { glm::vec3 v = render_data->material()->getVec3(it->second); glUniform3f(it->first, v.x, v.y, v.z); } for (auto it = uniform_vec4_keys_.begin(); it != uniform_vec4_keys_.end(); ++it) { glm::vec4 v = render_data->material()->getVec4(it->second); glUniform4f(it->first, v.x, v.y, v.z, v.w); } for (auto it = uniform_mat4_keys_.begin(); it != uniform_mat4_keys_.end(); ++it) { glm::mat4 m = render_data->material()->getMat4(it->second); glUniformMatrix4fv(it->first, 1, GL_FALSE, glm::value_ptr(m)); } glDrawElements(GL_TRIANGLES, mesh->triangles().size(), GL_UNSIGNED_SHORT, mesh->triangles().data()); #endif checkGlError("CustomShader::render"); }
Variable& Variable::operator<<(float value) { glUniform1f(mLocation, value); return *this; }
void ShaderPair::SetUniformVar(std::string varName, float val) { glUniform1f(GetUniformLocation(varName.c_str()), val); }
void Shader::setUniform(const char *name, float f) { GLint loc = getUniformLocation(name); glUniform1f(loc, f); }
bool CRendererMediaCodec::RenderHook(int index) { #ifdef DEBUG_VERBOSE unsigned int time = XbmcThreads::SystemClockMillis(); #endif YUVPLANE &plane = m_buffers[index].fields[0][0]; YUVPLANE &planef = m_buffers[index].fields[field][0]; glDisable(GL_DEPTH_TEST); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_EXTERNAL_OES, plane.id); if (field != FIELD_FULL) { g_Windowing.EnableGUIShader(SM_TEXTURE_RGBA_BOB_OES); GLint fieldLoc = g_Windowing.GUIShaderGetField(); GLint stepLoc = g_Windowing.GUIShaderGetStep(); // Y is inverted, so invert fields if (field == FIELD_TOP) glUniform1i(fieldLoc, 0); else if(field == FIELD_BOT) glUniform1i(fieldLoc, 1); glUniform1f(stepLoc, 1.0f / (float)plane.texheight); } else g_Windowing.EnableGUIShader(SM_TEXTURE_RGBA_OES); GLint contrastLoc = g_Windowing.GUIShaderGetContrast(); glUniform1f(contrastLoc, CMediaSettings::GetInstance().GetCurrentVideoSettings().m_Contrast * 0.02f); GLint brightnessLoc = g_Windowing.GUIShaderGetBrightness(); glUniform1f(brightnessLoc, CMediaSettings::GetInstance().GetCurrentVideoSettings().m_Brightness * 0.01f - 0.5f); glUniformMatrix4fv(g_Windowing.GUIShaderGetCoord0Matrix(), 1, GL_FALSE, m_textureMatrix); GLubyte idx[4] = {0, 1, 3, 2}; //determines order of triangle strip GLfloat ver[4][4]; GLfloat tex[4][4]; GLint posLoc = g_Windowing.GUIShaderGetPos(); GLint texLoc = g_Windowing.GUIShaderGetCoord0(); glVertexAttribPointer(posLoc, 4, GL_FLOAT, 0, 0, ver); glVertexAttribPointer(texLoc, 4, GL_FLOAT, 0, 0, tex); glEnableVertexAttribArray(posLoc); glEnableVertexAttribArray(texLoc); // Set vertex coordinates for(int i = 0; i < 4; i++) { ver[i][0] = m_rotatedDestCoords[i].x; ver[i][1] = m_rotatedDestCoords[i].y; ver[i][2] = 0.0f; // set z to 0 ver[i][3] = 1.0f; } // Set texture coordinates (MediaCodec is flipped in y) if (field == FIELD_FULL) { tex[0][0] = tex[3][0] = plane.rect.x1; tex[0][1] = tex[1][1] = plane.rect.y2; tex[1][0] = tex[2][0] = plane.rect.x2; tex[2][1] = tex[3][1] = plane.rect.y1; } else { tex[0][0] = tex[3][0] = planef.rect.x1; tex[0][1] = tex[1][1] = planef.rect.y2 * 2.0f; tex[1][0] = tex[2][0] = planef.rect.x2; tex[2][1] = tex[3][1] = planef.rect.y1 * 2.0f; } for(int i = 0; i < 4; i++) { tex[i][2] = 0.0f; tex[i][3] = 1.0f; } glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, idx); glDisableVertexAttribArray(posLoc); glDisableVertexAttribArray(texLoc); const float identity[16] = { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; glUniformMatrix4fv(g_Windowing.GUIShaderGetCoord0Matrix(), 1, GL_FALSE, identity); g_Windowing.DisableGUIShader(); VerifyGLState(); glBindTexture(GL_TEXTURE_EXTERNAL_OES, 0); VerifyGLState(); #ifdef DEBUG_VERBOSE CLog::Log(LOGDEBUG, "RenderMediaCodecImage %d: tm:%d", index, XbmcThreads::SystemClockMillis() - time); #endif return true; }
//OpenGL Initialization Logic void glInit() { glEnable(GL_TEXTURE_2D); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_POLYGON_OFFSET_LINE); glPolygonOffset(-1.f, -1.0f); glEnable(GL_MULTISAMPLE); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); int samples, bufs; glGetIntegerv(GL_SAMPLE_BUFFERS, &bufs); glGetIntegerv(GL_SAMPLES, &samples); printf("Multisampling buffers: %d, samples: %d\n", bufs, samples); glm::vec3 coneDir = {0.f, -1.f, -1.f}; glm::vec4 lightPos = {0.f, 30.f, 30.f, 1.f}; glm::mat4 scaleBiasMat = {{0.5f, 0.f, 0.f, 0.f}, {0.f, 0.5f, 0.f, 0.f}, {0.f, 0.f, 0.5f, 0.f}, {0.5f, 0.5f, 0.5f, 1.f}}; GLuint TeapotTexture; int imgWidth, imgHeight, imgComp; gTexImage = stbi_load("texture.jpg", &imgWidth, &imgHeight, &imgComp, STBI_rgb); glGenTextures(1, &TeapotTexture); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, TeapotTexture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, imgWidth, imgHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, gTexImage); glActiveTexture(GL_TEXTURE0); //Screen Shader gScreenProg = glCreateProgram(); gScreenVS = CreateShader(GL_VERTEX_SHADER, "screen.vert"); gScreenFS = CreateShader(GL_FRAGMENT_SHADER, "screen.frag"); glAttachShader(gScreenProg, gScreenVS); glAttachShader(gScreenProg, gScreenFS); glLinkProgram(gScreenProg); glUseProgram(gScreenProg); glm::vec3 screenColor = {1.f, 1.f, 1.f}; GLint screenColorLoc = glGetUniformLocation(gScreenProg, "uColor"); glUniform3fv(screenColorLoc, 1, glm::value_ptr(screenColor)); glGenVertexArrays(1, &gScreenVao); glBindVertexArray(gScreenVao); glGenBuffers(1, &gScreenPosBuf); glBindBuffer(GL_ARRAY_BUFFER, gScreenPosBuf); glm::vec4 screenPosData[] = {{-0.8f, -0.5f, 0.f, 1.f}, {-0.8f, -0.8f, 0.f, 1.f}, {-0.5f, -0.5f, 0.f, 1.f}, {-0.5f, -0.5f, 0.f, 1.f}, {-0.8f, -0.8f, 0.f, 1.f}, {-0.5f, -0.8f, 0.f, 1.f}}; glBufferData(GL_ARRAY_BUFFER, 6 * 4 * sizeof(float), &screenPosData[0], GL_STATIC_DRAW); GLint screenPosLoc = glGetAttribLocation(gScreenProg, "vPosition"); glEnableVertexAttribArray(screenPosLoc); glBindBuffer(GL_ARRAY_BUFFER, gScreenPosBuf); glVertexAttribPointer(screenPosLoc, 4, GL_FLOAT, GL_FALSE, 0, NULL); //Shadow Map Creation gShadowProg = glCreateProgram(); gShadowVS = CreateShader(GL_VERTEX_SHADER, "shadow.vert"); gShadowFS = CreateShader(GL_FRAGMENT_SHADER, "shadow.frag"); glAttachShader(gShadowProg, gShadowVS); glAttachShader(gShadowProg, gShadowFS); glLinkProgram(gShadowProg); glUseProgram(gShadowProg); glGenFramebuffers(1, &gShadowFbo); glBindFramebuffer(GL_FRAMEBUFFER, gShadowFbo); glDrawBuffer(GL_NONE); glGenTextures(1, &gShadowTexture); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, gShadowTexture); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, SHADOW_DEPTH_TEXTURE_SIZE, SHADOW_DEPTH_TEXTURE_SIZE, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glActiveTexture(GL_TEXTURE0); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, gShadowTexture, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0); gShadowViewMat = glm::lookAt(glm::vec3(lightPos), glm::vec3(lightPos) + coneDir, glm::vec3(0, 1, 0)); gShadowProjMat = glm::frustum(-1.f, 1.f, -1.f, 1.f, 1.f, SHADOW_FRUSTRUM_DEPTH); gShadowModelMatLoc = glGetUniformLocation(gShadowProg, "uModelMat"); gShadowViewMatLoc = glGetUniformLocation(gShadowProg, "uViewMat"); glUniformMatrix4fv(gShadowViewMatLoc, 1, GL_FALSE, glm::value_ptr(gShadowViewMat)); gShadowProjMatLoc = glGetUniformLocation(gShadowProg, "uProjMat"); glUniformMatrix4fv(gShadowProjMatLoc, 1, GL_FALSE, glm::value_ptr(gShadowProjMat)); glGenVertexArrays(1, &gShadowVao); glBindVertexArray(gShadowVao); gShadowPosLoc = glGetAttribLocation(gShadowProg, "vPosition"); glEnableVertexAttribArray(gShadowPosLoc); //Program Creation gRenderProg = glCreateProgram(); gRenderVS = CreateShader(GL_VERTEX_SHADER, "shader.vert"); gRenderFS = CreateShader(GL_FRAGMENT_SHADER, "shader.frag"); glAttachShader(gRenderProg, gRenderVS); glAttachShader(gRenderProg, gRenderFS); glLinkProgram(gRenderProg); glUseProgram(gRenderProg); //Texture //Uniforms gModelMatLoc = glGetUniformLocation(gRenderProg, "uModelMat"); gModelMat = glm::rotate(glm::mat4(1.f), -1.57f, glm::vec3(1.f, 0.f, 0.f)); glUniformMatrix4fv(gModelMatLoc, 1, GL_FALSE, glm::value_ptr(gModelMat)); gViewMatLoc = glGetUniformLocation(gRenderProg, "uViewMat"); glm::mat4 viewMat = glm::mat4(1.f); viewMat = glm::rotate(glm::mat4(1.f), 0.7f, glm::vec3(1.f, 0.f, 0.f)) * viewMat; viewMat = glm::translate(glm::mat4(1.f), glm::vec3(0.f, 0.f, -50.f)) * viewMat; glUniformMatrix4fv(gViewMatLoc, 1, GL_FALSE, glm::value_ptr(viewMat)); gProjMatLoc = glGetUniformLocation(gRenderProg, "uProjMat"); glm::mat4 projMat = glm::perspective(45.f, (float)gScreenWidth / (float)gScreenHeight, PROJ_NEAR, PROJ_FAR); glUniformMatrix4fv(gProjMatLoc, 1, GL_FALSE, glm::value_ptr(projMat)); gScaleBiasMatLoc = glGetUniformLocation(gRenderProg, "uScaleBiasMat"); glUniformMatrix4fv(gScaleBiasMatLoc, 1, GL_FALSE, glm::value_ptr(scaleBiasMat)); gShadowMatLoc = glGetUniformLocation(gRenderProg, "uShadowMat"); glm::mat4 shadowMat = gShadowProjMat * gShadowViewMat; glUniformMatrix4fv(gShadowMatLoc, 1, GL_FALSE, glm::value_ptr(shadowMat)); gTexUnitLoc = glGetUniformLocation(gRenderProg, "uTexUnit"); glUniform1i(gTexUnitLoc, 0); gIsTexturedLoc = glGetUniformLocation(gRenderProg, "uIsTextured"); glUniform1i(gIsTexturedLoc, 1); gColorLoc = glGetUniformLocation(gRenderProg, "uColor"); glm::vec4 color = {1.0f, 0.f, 0.f, 1.f}; glUniform4fv(gColorLoc, 1, glm::value_ptr(color)); gAmbientLoc = glGetUniformLocation(gRenderProg, "uAmbient"); glm::vec3 ambVec = {0.3f, 0.3f, 0.3f}; glUniform3fv(gAmbientLoc, 1, glm::value_ptr(ambVec)); gDiffuseLoc = glGetUniformLocation(gRenderProg, "uDiffuse"); glm::vec3 difVec = {0.5f, 0.f, 0.f}; glUniform3fv(gDiffuseLoc, 1, glm::value_ptr(difVec)); gSpecularLoc = glGetUniformLocation(gRenderProg, "uSpecular"); glm::vec3 specVec = {1.f, 1.f, 1.f}; glUniform3fv(gSpecularLoc, 1, glm::value_ptr(specVec)); gShininessLoc = glGetUniformLocation(gRenderProg, "uShininess"); float shininess = 20.0f; glUniform1f(gShininessLoc, shininess); gLightPosLoc = glGetUniformLocation(gRenderProg, "uLightPos"); glUniform4fv(gLightPosLoc, 1, glm::value_ptr(lightPos)); gSpecStrengthLoc = glGetUniformLocation(gRenderProg, "uSpecStrength"); float strength = 3.f; glUniform1f(gSpecStrengthLoc, strength); gConstAttenuationLoc = glGetUniformLocation(gRenderProg, "uConstAttenuation"); float constAttenuation = 1.f; glUniform1f(gConstAttenuationLoc, constAttenuation); gLinearAttenuationLoc = glGetUniformLocation(gRenderProg, "uLinearAttenuation"); float linearAttenuation = 0.05f; glUniform1f(gLinearAttenuationLoc, linearAttenuation); gConeDirectionLoc = glGetUniformLocation(gRenderProg, "uConeDirection"); glUniform3fv(gConeDirectionLoc, 1, glm::value_ptr(coneDir)); gConeAngleLoc = glGetUniformLocation(gRenderProg, "uConeAngle"); float coneAngle = 0.8f; glUniform1f(gConeAngleLoc, coneAngle); gSpotExponentLoc = glGetUniformLocation(gRenderProg, "uSpotExponent"); float spotExponent = 1.0f; glUniform1f(gSpotExponentLoc, spotExponent); gAmbientSkyLoc = glGetUniformLocation(gRenderProg, "uAmbientSky"); glm::vec3 ambientSky = {0.3f, 0.3f, 0.3f}; glUniform3fv(gAmbientSkyLoc, 1, glm::value_ptr(ambientSky)); gAmbientGroundLoc = glGetUniformLocation(gRenderProg, "uAmbientGround"); glm::vec3 ambientGround = {0.1f, 0.1f, 0.1f}; glUniform3fv(gAmbientGroundLoc, 1, glm::value_ptr(ambientGround)); gDepthTextureLoc = glGetUniformLocation(gRenderProg, "uDepthTexture"); glUniform1i(gDepthTextureLoc, 2); gProjectorDepthTextureLoc = glGetUniformLocation(gRenderProg, "uProjectorDepthTexture"); glUniform1i(gProjectorDepthTextureLoc, 3); //Vertex Array Object glGenVertexArrays(1, &gVao); glBindVertexArray(gVao); //Vertex Attribute Specification gPosLoc = glGetAttribLocation(gRenderProg, "vPosition"); glEnableVertexAttribArray(gPosLoc); gTexCoordLoc = glGetAttribLocation(gRenderProg, "vTexCoord"); glEnableVertexAttribArray(gTexCoordLoc); gNormLoc = glGetAttribLocation(gRenderProg, "vNormal"); glEnableVertexAttribArray(gNormLoc); //Floor gFloorObj.modelMat = glm::mat4(1.f); GLuint floorBuffers[3]; glGenBuffers(3, &floorBuffers[0]); glBindBuffer(GL_ARRAY_BUFFER, floorBuffers[0]); glm::vec4 floorPosData[] = {{-60.f, 0.f, -30.f, 1.f}, {-60, 0.f, 30.f, 1.f}, {60.f, 0.f, -30.f, 1.f}, {60.f, 0.f, -30.f, 1.f}, {-60.f, 0.f, 30.f, 1.f}, {60.f, 0.f, 30.f, 1.f}}; glBufferData(GL_ARRAY_BUFFER, 4 * 6 * sizeof(float), &floorPosData[0], GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, floorBuffers[1]); glm::vec2 floorTexCoordData[] = {{0.f, 0.f}, {0.f, 1.f}, {1.f, 0.f}, {1.f, 0.f}, {0.f, 1.f}, {1.f, 1.f}}; glBufferData(GL_ARRAY_BUFFER, 2 * 6 * sizeof(float), &floorTexCoordData[0], GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, floorBuffers[2]); glm::vec3 floorNormData[] = {{0.f, 1.f, 0.f}, {0.f, 1.f, 0.f}, {0.f, 1.f, 0.f}, {0.f, 1.f, 0.f}, {0.f, 1.f, 0.f}, {0.f, 1.f, 0.f}}; glBufferData(GL_ARRAY_BUFFER, 3 * 6 * sizeof(float), &floorNormData[0], GL_STATIC_DRAW); gFloorObj.glPosBuf = floorBuffers[0]; gFloorObj.glTexCoordBuf = floorBuffers[1]; gFloorObj.glNormBuf = floorBuffers[2]; gFloorObj.vertCount = 6; gFloorObj.ambientColor = {0.3f, 0.3f, 0.3f}; //gFloorObj.ambientColor = {1.f, 1.f, 1.f}; gFloorObj.diffuseColor = {0.5f, 0.5f, 0.5f}; gFloorObj.specularColor = {1.f, 1.f, 1.f}; gFloorObj.shininess = 20.f; gFloorObj.specStrength = 0.f; gFloorObj.isTextured = false; gFloorObj.objColor = {0.5f, 0.5f, 0.5f, 1.f}; //gFloorObj.objColor = {1.f, 1.f, 1.f, 1.f}; gFloorObj.glTexture = TeapotTexture; gFloorObj.glTexUnit = 0; //Teapot gTeapotObj.modelMat = glm::rotate(glm::mat4(1.f), -1.57f, glm::vec3(1.f, 0.f, 0.f)); GLuint TeapotBuffers[3]; glGenBuffers(3, &TeapotBuffers[0]); glBindBuffer(GL_ARRAY_BUFFER, TeapotBuffers[0]); glBufferData(GL_ARRAY_BUFFER, teapot.m_Info.vertCount * 4 * sizeof(float), &teapot.m_Info.v[0], GL_STREAM_DRAW); glBindBuffer(GL_ARRAY_BUFFER, TeapotBuffers[1]); glBufferData(GL_ARRAY_BUFFER, teapot.m_Info.vertCount * 2 * sizeof(float), &teapot.m_Info.vt[0], GL_STREAM_DRAW); glBindBuffer(GL_ARRAY_BUFFER, TeapotBuffers[2]); glBufferData(GL_ARRAY_BUFFER, teapot.m_Info.vertCount * 3 * sizeof(float), &teapot.m_Info.vn[0], GL_STREAM_DRAW); gTeapotObj.glPosBuf = TeapotBuffers[0]; gTeapotObj.glTexCoordBuf = TeapotBuffers[1]; gTeapotObj.glNormBuf = TeapotBuffers[2]; gTeapotObj.vertCount = teapot.m_Info.vertCount; gTeapotObj.ambientColor = {0.3f, 0.3f, 0.3f}; gTeapotObj.diffuseColor = {0.8f, 0.f, 0.f}; gTeapotObj.specularColor = {1.f, 1.f, 1.f}; gTeapotObj.shininess = 20.f; gTeapotObj.specStrength = 5.f; gTeapotObj.isTextured = true; gTeapotObj.objColor = {0.1f, 0.f, 0.f, 1.f}; gTeapotObj.glTexture = TeapotTexture; gTeapotObj.glTexUnit = 1; gSceneGraph.push_back(gTeapotObj); gSceneGraph.push_back(gFloorObj); gFilterProg = glCreateProgram(); gFilterVS = CreateShader(GL_VERTEX_SHADER, "bloom.vert"); gFilterFS = CreateShader(GL_FRAGMENT_SHADER, "bloom.frag"); glAttachShader(gFilterProg, gFilterVS); glAttachShader(gFilterProg, gFilterFS); glLinkProgram(gFilterProg); glUseProgram(gFilterProg); gFilterRenderTextureLoc = glGetUniformLocation(gFilterProg, "uRenderTexture"); glUniform1i(gFilterRenderTextureLoc, 3); // Swap textures in shader by binding texture to tex unit 4 (GL_TEXTURE3) gFilterTextureLoc = glGetUniformLocation(gFilterProg, "uTexture"); glUniform1i(gFilterTextureLoc, 4); gFilterWidthLoc = glGetUniformLocation(gFilterProg, "uScreenWidth"); glUniform1i(gFilterWidthLoc, gScreenWidth * 2); gFilterHeightLoc = glGetUniformLocation(gFilterProg, "uScreenHeight"); glUniform1i(gFilterHeightLoc, gScreenHeight * 2); gFilterPassLoc = glGetUniformLocation(gFilterProg, "uPass"); glUniform1i(gFilterPassLoc, 1); gFilterLumThresholdLoc = glGetUniformLocation(gFilterProg, "uLumThreshold"); glUniform1f(gFilterLumThresholdLoc, 0.75f); // Calculates the weights of the gaussian function float weights[20]; float sum = 0.f; float sigma = 5.f; weights[0] = gauss(0, sigma); sum += weights[0]; for (int i = 1; i < 20; i++) { weights[i] = gauss(i, sigma); sum += 2 * weights[i]; } for (int i = 0; i < 20; i++) { weights[i] = weights[i] / sum; // Normalizes weights: sum of weights equals 1 } gFilterWeightsLoc = glGetUniformLocation(gFilterProg, "uWeights"); glUniform1fv(gFilterWeightsLoc, 20, weights); glGenBuffers(1, &gFilterPosBuf); glBindBuffer(GL_ARRAY_BUFFER, gFilterPosBuf); glm::vec4 filterPosData[] = {{-1.f, 1.f, 0.f, 1.f}, {-1.f, -1.f, 0.f, 1.f}, {1.f, 1.f, 0.f, 1.f}, {1.f, 1.f, 0.f, 1.f}, {-1.f, -1.f, 0.f, 1.f}, {1.f, -1.f, 0.f, 1.f}}; glBufferData(GL_ARRAY_BUFFER, 6 * 4 * sizeof(float), &filterPosData[0], GL_STATIC_DRAW); glGenBuffers(1, &gFilterTexCoordBuf); glBindBuffer(GL_ARRAY_BUFFER, gFilterTexCoordBuf); glm::vec2 filterTexCoordData[] = {{0.f, 1.f}, {0.f, 0.f}, {1.f, 1.f}, {1.f, 1.f}, {0.f, 0.f}, {1.f, 0.f}}; glBufferData(GL_ARRAY_BUFFER, 6 * 2 * sizeof(float), &filterTexCoordData[0], GL_STATIC_DRAW); glGenVertexArrays(1, &gFilterVao); glBindVertexArray(gFilterVao); gFilterPosBufLoc = glGetAttribLocation(gFilterProg, "vPosition"); glEnableVertexAttribArray(gFilterPosBufLoc); glBindBuffer(GL_ARRAY_BUFFER, gFilterPosBuf); glVertexAttribPointer(gFilterPosBufLoc, 4, GL_FLOAT, GL_FALSE, 0, NULL); gFilterTexCoordBufLoc = glGetAttribLocation(gFilterProg, "vTexCoord"); glEnableVertexAttribArray(gFilterTexCoordBufLoc); glBindBuffer(GL_ARRAY_BUFFER, gFilterTexCoordBuf); glVertexAttribPointer(gFilterTexCoordBufLoc, 2, GL_FLOAT, GL_FALSE, 0, NULL); // Scene rendered to gFilterSceneTexture glGenFramebuffers(1, &gFilterSceneFbo); glBindFramebuffer(GL_FRAMEBUFFER, gFilterSceneFbo); glGenTextures(1, &gFilterSceneTexture); glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, gFilterSceneTexture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, gScreenWidth * 2, gScreenHeight * 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glActiveTexture(GL_TEXTURE0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, gFilterSceneTexture, 0); glGenRenderbuffers(1, &gFilterSceneRbo); glBindRenderbuffer(GL_RENDERBUFFER, gFilterSceneRbo); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, gScreenWidth * 2, gScreenHeight * 2); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, gFilterSceneRbo); GLenum drawModes[1] = {GL_COLOR_ATTACHMENT0}; glDrawBuffers(1, drawModes); glBindFramebuffer(GL_FRAMEBUFFER, 0); // Results of low luminance discard stored in gFilterLumTexture glGenFramebuffers(1, &gFilterLumFbo); glBindFramebuffer(GL_FRAMEBUFFER, gFilterLumFbo); glGenTextures(1, &gFilterLumTexture); glBindTexture(GL_TEXTURE_2D, gFilterLumTexture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, gScreenWidth * 2, gScreenHeight * 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, gFilterLumTexture, 0); GLenum lumDrawModes[1] = {GL_COLOR_ATTACHMENT0}; glDrawBuffers(1, lumDrawModes); glBindFramebuffer(GL_FRAMEBUFFER, 0); // Results of gaussian filter pass1 stored in gFilterPassTexture (depth buffer not needed) glGenFramebuffers(1, &gFilterBlurFbo); glBindFramebuffer(GL_FRAMEBUFFER, gFilterBlurFbo); glGenTextures(1, &gFilterBlurTexture); glBindTexture(GL_TEXTURE_2D, gFilterBlurTexture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, gScreenWidth * 2, gScreenHeight * 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, gFilterBlurTexture, 0); GLenum passDrawModes[1] = {GL_COLOR_ATTACHMENT0}; glDrawBuffers(1, passDrawModes); glBindFramebuffer(GL_FRAMEBUFFER, 0); }
//OpenGL Loop Logic void glLoop() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /*gModelMat = glm::rotate(gModelMat, -0.01f, glm::vec3(0.f, 0.f, 1.f)); glUniformMatrix4fv(gModelMatLoc, 1, GL_FALSE, glm::value_ptr(gModelMat));*/ glBindFramebuffer(GL_FRAMEBUFFER, gShadowFbo); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glUseProgram(gShadowProg); glBindVertexArray(gShadowVao); glViewport(0, 0, SHADOW_DEPTH_TEXTURE_SIZE, SHADOW_DEPTH_TEXTURE_SIZE); glClearDepth(1.0f); glClear(GL_DEPTH_BUFFER_BIT); glUniformMatrix4fv(gShadowViewMatLoc, 1, GL_FALSE, glm::value_ptr(gShadowViewMat)); glUniformMatrix4fv(gShadowProjMatLoc, 1, GL_FALSE, glm::value_ptr(gShadowProjMat)); glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(2.f, 4.f); for (auto& e: gSceneGraph) { glUniformMatrix4fv(gShadowModelMatLoc, 1, GL_FALSE, glm::value_ptr(e.modelMat)); glBindBuffer(GL_ARRAY_BUFFER, e.glPosBuf); glVertexAttribPointer(gShadowPosLoc, 4, GL_FLOAT, GL_FALSE, 0, NULL); glDrawArrays(GL_TRIANGLES, 0, e.vertCount); } glDisable(GL_POLYGON_OFFSET_FILL); glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewport(0, 0, gScreenWidth * 2, gScreenHeight * 2); // Renders Scene to gFilterSceneTexture glBindFramebuffer(GL_FRAMEBUFFER, gFilterSceneFbo); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glUseProgram(gRenderProg); glBindVertexArray(gVao); for (auto& e: gSceneGraph) { glUniformMatrix4fv(gModelMatLoc, 1, GL_FALSE, glm::value_ptr(e.modelMat)); glUniform3fv(gAmbientLoc, 1, glm::value_ptr(e.ambientColor)); glUniform3fv(gDiffuseLoc, 1, glm::value_ptr(e.diffuseColor)); glUniform3fv(gSpecularLoc, 1, glm::value_ptr(e.specularColor)); glUniform1f(gShininessLoc, e.shininess); glUniform1f(gSpecStrengthLoc, e.specStrength); glUniform1i(gIsTexturedLoc, e.isTextured); glUniform1i(gTexUnitLoc, e.glTexUnit); glUniform4fv(gColorLoc, 1, glm::value_ptr(e.objColor)); glBindBuffer(GL_ARRAY_BUFFER, e.glPosBuf); glVertexAttribPointer(gPosLoc, 4, GL_FLOAT, GL_FALSE, 0, NULL); glBindBuffer(GL_ARRAY_BUFFER, e.glTexCoordBuf); glVertexAttribPointer(gTexCoordLoc, 2, GL_FLOAT, GL_FALSE, 0, NULL); glBindBuffer(GL_ARRAY_BUFFER, e.glNormBuf); glVertexAttribPointer(gNormLoc, 3, GL_FLOAT, GL_FALSE, 0, NULL); glDrawArrays(GL_TRIANGLES, 0, e.vertCount); } glUseProgram(gScreenProg); glBindVertexArray(gScreenVao); glDrawArrays(GL_TRIANGLES, 0, 3); glBindFramebuffer(GL_FRAMEBUFFER, 0); // Low luminance discard pass. Results stored in gFilterLumTexture glBindFramebuffer(GL_FRAMEBUFFER, gFilterLumFbo); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glUseProgram(gFilterProg); glUniform1i(gFilterPassLoc, 1); glBindVertexArray(gFilterVao); glDrawArrays(GL_TRIANGLES, 0, 6); glBindFramebuffer(GL_FRAMEBUFFER, 0); // Vertical pass of gaussian filter. Results stored in gFilterBlurTexture glViewport(0, 0, gScreenWidth * 2, gScreenHeight * 2); glActiveTexture(GL_TEXTURE4); glBindTexture(GL_TEXTURE_2D, gFilterLumTexture); // Texture obtained from scene rendering glActiveTexture(GL_TEXTURE0); glBindFramebuffer(GL_FRAMEBUFFER, gFilterBlurFbo); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glUseProgram(gFilterProg); glUniform1i(gFilterPassLoc, 2); glBindVertexArray(gFilterVao); glDrawArrays(GL_TRIANGLES, 0, 6); glBindFramebuffer(GL_FRAMEBUFFER, 0); // Horizontal pass of gaussian filter. Rendered to default framebuffer (screen) glActiveTexture(GL_TEXTURE4); glBindTexture(GL_TEXTURE_2D, gFilterBlurTexture); // Texture obtained from pass 1 of gaussian filter glActiveTexture(GL_TEXTURE0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glUseProgram(gFilterProg); glUniform1i(gFilterPassLoc, 3); glBindVertexArray(gFilterVao); glDrawArrays(GL_TRIANGLES, 0, 6); }
void set(const std::string& name, double value) { GL(glUniform1f(get_location(name.c_str()), static_cast<float>(value))); }
void set(const std::string& name, float value) { GL(glUniform1f(get_location(name.c_str()), value)); }
//-------------------------------------------------------------- void ofShader::setUniform1f(const string & name, float v1) const{ if(bLoaded) { int loc = getUniformLocation(name); if (loc != -1) glUniform1f(loc, v1); } }
void display (void) { static int frames, last_time; int x0, y0, width, height, ticks; GLint uindex; struct timespec ts; glUseProgram (prog); x0 = glutGet (GLUT_WINDOW_X); y0 = glutGet (GLUT_WINDOW_Y); width = glutGet (GLUT_WINDOW_WIDTH); height = glutGet (GLUT_WINDOW_HEIGHT); clock_gettime (CLOCK_MONOTONIC_RAW, &ts); ticks = ts.tv_sec * 1000 + ts.tv_nsec / 1000000; if(start_time == 0) start_time = ticks; if (frames == 0) last_time = ticks; frames++; if (ticks - last_time >= 5000) { fprintf (stderr, "FPS: %.2f\n", 1000.0 * frames / (ticks - last_time)); frames = 0; } uindex = glGetUniformLocation (prog, "iGlobalTime"); if (uindex >= 0) glUniform1f (uindex, (ticks - start_time) / 1000.0); uindex = glGetUniformLocation (prog, "time"); if (uindex >= 0) glUniform1f (uindex, (ticks - start_time) / 1000.0); uindex = glGetUniformLocation (prog, "iResolution"); if (uindex >= 0) { if (geometry[0] > 0.1 && geometry[1] > 0.1) glUniform3f (uindex, geometry[0], geometry[1], 1.0); else glUniform3f (uindex, width, height, 1.0); } uindex = glGetUniformLocation (prog, "iOffset"); if (uindex >= 0) { if (geometry[0] > 0.1 && geometry[1] > 0.1) { glUniform2f (uindex, x0 + geometry[2], geometry[1] - (y0 + height) - geometry[3]); } else { glUniform2f (uindex, 0.0, 0.0); } } uindex = glGetUniformLocation (prog, "iMouse"); if (uindex >= 0) glUniform4f (uindex, mouse[0], mouse[1], mouse[2], mouse[3]); uindex = glGetUniformLocation (prog, "iChannel0"); if (uindex >= 0) { glActiveTexture (GL_TEXTURE0 + 0); glBindTexture (GL_TEXTURE_2D, tex[0]); glUniform1i (uindex, 0); } uindex = glGetUniformLocation (prog, "iChannel1"); if (uindex >= 0) { glActiveTexture (GL_TEXTURE0 + 1); glBindTexture (GL_TEXTURE_2D, tex[1]); glUniform1i (uindex, 1); } uindex = glGetUniformLocation (prog, "iChannel2"); if (uindex >= 0) { glActiveTexture (GL_TEXTURE0 + 2); glBindTexture (GL_TEXTURE_2D, tex[1]); glUniform1i (uindex, 2); } uindex = glGetUniformLocation (prog, "iChannel3"); if (uindex >= 0) { glActiveTexture (GL_TEXTURE0 + 3); glBindTexture (GL_TEXTURE_2D, tex[1]); glUniform1i (uindex, 3); } uindex = glGetUniformLocation (prog, "resolution"); if (uindex >= 0) { if (geometry[0] > 0.1 && geometry[1] > 0.1) glUniform2f (uindex, geometry[0], geometry[1]); else glUniform2f (uindex, width, height); } uindex = glGetUniformLocation (prog, "led_color"); if (uindex >= 0) glUniform3f (uindex, 0.5, 0.3, 0.8); glClear (GL_COLOR_BUFFER_BIT); glRectf (-1.0, -1.0, 1.0, 1.0); glutSwapBuffers (); }
void GLLineShader2D::setZoom(float zoom) { glUniform1f(uniform_zoom, zoom); check_gl("Set line zoom level"); }
int BrightnessMain::handle_opengl() { #ifdef HAVE_GL static char *brightness_yuvluma_frag = "uniform sampler2D tex;\n" "uniform float brightness;\n" "uniform float contrast;\n" "uniform float offset;\n" "void main()\n" "{\n" " vec4 yuva = texture2D(tex, gl_TexCoord[0].st);\n" " yuva.r += brightness;\n" " yuva.r = yuva.r * contrast + offset;\n" " gl_FragColor = yuva;\n" "}\n"; static char *brightness_yuv_frag = "uniform sampler2D tex;\n" "uniform float brightness;\n" "uniform float contrast;\n" "uniform float offset;\n" "void main()\n" "{\n" " vec4 yuva = texture2D(tex, gl_TexCoord[0].st);\n" " yuva.r += brightness;\n" " yuva.rgb *= vec3(contrast, contrast, contrast);\n" " yuva.rgb += vec3(offset, offset, offset);\n" " gl_FragColor = yuva;\n" "}\n"; static char *brightness_rgb_frag = "uniform sampler2D tex;\n" "uniform float brightness;\n" "uniform float contrast;\n" "uniform float offset;\n" "void main()\n" "{\n" " vec4 rgba = texture2D(tex, gl_TexCoord[0].st);\n" " rgba.rgb += vec3(brightness, brightness, brightness);\n" " rgba.rgb *= vec3(contrast, contrast, contrast);\n" " rgba.rgb += vec3(offset, offset, offset);\n" " gl_FragColor = rgba;\n" "}\n"; static char *brightness_rgbluma_frag = "uniform sampler2D tex;\n" "uniform float brightness;\n" "uniform float contrast;\n" "uniform float offset;\n" "void main()\n" "{\n" " const mat3 yuv_to_rgb_matrix = mat3(\n" " 1, 1, 1, \n" " 0, -0.34414, 1.77200, \n" " 1.40200, -0.71414, 0);\n" " const mat3 rgb_to_yuv_matrix = mat3(\n" " 0.29900, -0.16874, 0.50000, \n" " 0.58700, -0.33126, -0.41869, \n" " 0.11400, 0.50000, -0.08131);\n" " vec4 rgba = texture2D(tex, gl_TexCoord[0].st);\n" " rgba.rgb = rgb_to_yuv_matrix * rgba.rgb;\n" " rgba.r += brightness;\n" " rgba.r = rgba.r * contrast + offset;\n" " rgba.rgb = yuv_to_rgb_matrix * rgba.rgb;\n" " gl_FragColor = rgba;\n" "}\n"; get_output()->to_texture(); get_output()->enable_opengl(); unsigned int shader_id = 0; switch(get_output()->get_color_model()) { case BC_YUV888: case BC_YUVA8888: if(config.luma) shader_id = VFrame::make_shader(0, brightness_yuvluma_frag, 0); else shader_id = VFrame::make_shader(0, brightness_yuv_frag, 0); break; default: if(config.luma) shader_id = VFrame::make_shader(0, brightness_rgbluma_frag, 0); else shader_id = VFrame::make_shader(0, brightness_rgb_frag, 0); break; } if(shader_id > 0) { glUseProgram(shader_id); glUniform1i(glGetUniformLocation(shader_id, "tex"), 0); glUniform1f(glGetUniformLocation(shader_id, "brightness"), config.brightness / 100); float contrast = (config.contrast < 0) ? (config.contrast + 100) / 100 : (config.contrast + 25) / 25; glUniform1f(glGetUniformLocation(shader_id, "contrast"), contrast); float offset = 0.5 - contrast / 2; glUniform1f(glGetUniformLocation(shader_id, "offset"), offset); } get_output()->init_screen(); get_output()->bind_texture(0); get_output()->draw_texture(); glUseProgram(0); get_output()->set_opengl_state(VFrame::SCREEN); //printf("BrightnessMain::handle_opengl 100 %x\n", glGetError()); #endif }
void MaterialPreview::paintGL() { // clear framebuffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // set modelview matrix glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMultMatrix(camera_->getCameraMatrix().constData()); shadingProgram->bind(); glLightfv(GL_LIGHT0, GL_POSITION, light0Position_); // set uniforms for the sphere glUniform1f(shadingIdID_, sphere_->getID()); glUniform3f(ambientColorID_, sphere_->getAmbientColor().x_, sphere_->getAmbientColor().y_, sphere_->getAmbientColor().z_); glUniform3f(diffuseColorID_, sphere_->getDiffuseColor().x_, sphere_->getDiffuseColor().y_, sphere_->getDiffuseColor().z_); glUniform3f(specularColorID_, sphere_->getSpecularColor().x_, sphere_->getSpecularColor().y_, sphere_->getSpecularColor().z_); glUniform1f(kaID_, sphere_->getKa()); glUniform1f(kdID_, sphere_->getKd()); glUniform1f(ksID_, sphere_->getKs()); glUniform1f(roughnessID_, sphere_->getRoughness()); glUniform1f(specularRoughnessID_, sphere_->getSpecularRoughness()); glUniform1f(refractionIndexID_, sphere_->getRefractionIndex()); int *textureIDs = (int*) malloc(sizeof(int) * Primitive::NR_TEXTURES); int *textureActiveIDs = (int*) malloc(sizeof(int) * Primitive::NR_TEXTURES); for (int i = 0; i < Primitive::NR_TEXTURES; i++) { textureIDs[i] = 10 + i; if (sphere_->isTextureActive(static_cast<Primitive::Textures>(i))) { textureActiveIDs[i] = 1; } else { textureActiveIDs[i] = 0; } if (sphereBufferIDs_.hasTextures_[i]) { glActiveTexture(GL_TEXTURE10 + i); glBindTexture(GL_TEXTURE_2D, sphereBufferIDs_.textures_[i]); } else { glActiveTexture(GL_TEXTURE10 + i); glBindTexture(GL_TEXTURE_2D, 0); textureActiveIDs[i] = 0; } } glActiveTexture(GL_TEXTURE0); checkGLErrors("binding textures to master shader"); glUniform1iv(textureIDs_, Primitive::NR_TEXTURES, textureIDs); glUniform1iv(textureActiveIDs_, Primitive::NR_TEXTURES, textureActiveIDs); glUniform1i(nrTexturesID_, Primitive::NR_TEXTURES); glUniform1i(diffuseShaderID_, sphere_->getDiffuseShader()); glUniform1i(specularShaderID_, sphere_->getSpecularShader()); sphere_->draw(sphereBufferIDs_); shadingProgram->release(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (height() != 0) gluPerspective(45.0d, ((double) width()) / ((double) height()), NEAR_PLANE, FAR_PLANE); checkGLErrors("after setting projection matrix"); }
void ShaderLibrary::setUniformVariable(GLuint program, GLint location, double value) { glUniform1f(location, (GLfloat)value); }
void ParticleRenderer::display() { if (b_renderSkyBox){ drawSkyBox(); } if (b_renderFloor){ drawFloor(); } switch (_displayMode) { case PARTICLE_POINTS: { glColor3f(1, 1, 1); glPointSize(1.0f); _drawPoints(); } break; case PARTICLE_FIRE: { glPointSize(4.0f); float m_baseColor[4] = { 0.6f, 0.1f, 0.0f, 0.95f}; glColor4f(m_baseColor[0],m_baseColor[1],m_baseColor[2],m_baseColor[3]); glEnable (GL_POINT_SMOOTH); glHint (GL_POINT_SMOOTH_HINT, GL_NICEST); glAlphaFunc(GL_GREATER, 0.1); glEnable(GL_ALPHA_TEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glEnable(GL_BLEND); glDepthMask(GL_FALSE); // Disable depth buffer updating! (Integral to transparency!) _drawPoints(false); glDepthMask(GL_TRUE); glDisable(GL_BLEND); glDisable(GL_ALPHA_TEST); } break; case SPRITE_COSMOS: { glEnable(GL_POINT_SPRITE_ARB); // setup point sprites glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE); glEnable(GL_VERTEX_PROGRAM_POINT_SIZE_NV); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glEnable(GL_BLEND); glDepthMask(GL_FALSE); glUseProgram(m_program_cosmos); GLuint texLoc = glGetUniformLocation(m_program_cosmos, "splatTexture"); glUniform1i(texLoc, 0); glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_2D, m_texture); glColor3f(1, 1, 1); glPointSize(m_particleRadius*2.0f); //float m_baseColor[4] = {0.6f, 0.1f, 0.0f, 0.95f}; float m_baseColor[4] = { 1.0f, 0.6f, 0.3f, 0.20f}; // nbody fp32 color (yellow) //float m_baseColor[4] = { 0.4f, 0.8f, 0.1f, 1.0f}; // nbody fp64 color (green) glSecondaryColor3fv(m_baseColor); _drawPoints(); glUseProgram(0); glDisable(GL_POINT_SPRITE_ARB); glDisable(GL_BLEND); glDepthMask(GL_TRUE); } break; default: case PARTICLE_SPHERES: { glEnable(GL_POINT_SPRITE_ARB); glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE); glEnable(GL_VERTEX_PROGRAM_POINT_SIZE_NV); glDepthMask(GL_TRUE); glEnable(GL_DEPTH_TEST); glUseProgram(m_program_sphere); glUniform1f( glGetUniformLocation(m_program_sphere, "pointScale"), m_window_h / tanf(m_fov*0.5f*(float)M_PI/180.0f) ); glUniform1f( glGetUniformLocation(m_program_sphere, "pointRadius"), m_particleRadius ); glColor3f(1, 1, 1); _drawPoints(); glUseProgram(0); glDisable(GL_POINT_SPRITE_ARB); } break; } }
void ShaderPair::ModifyShaderVal(std::string varName, float val) { shaderVars[varName].fValue = val; glUniform1f(shaderVars[varName].location, val); }
void Shader::SetAmbientComponent(glm::vec3 color, float intensity) { glUseProgram(ProgramID); glUniform3f(ambientColorID, color.r, color.g, color.b); glUniform1f(ambientIntensityID, intensity); }
template<> void Program::set_uniform(int loc, const double& v) const { CHECK_FOR_GL_ERROR; glUniform1f(loc, (float)v); CHECK_FOR_GL_ERROR; }
void Shader::SetReflectFactor(float reflectFactor) { glUseProgram(ProgramID); glUniform1f(ReflectFactorID, reflectFactor); }
GameMain::GameMain(Engine *engine) : editor_current_terrain{0}, editor_current_building{0}, clicking_active{true}, ctrl_active{false}, scrolling_active{false}, assetmanager{engine->get_data_dir()} { engine->register_draw_action(this); engine->register_input_action(this); engine->register_tick_action(this); engine->register_drawhud_action(this); util::Dir *data_dir = engine->get_data_dir(); util::Dir asset_dir = data_dir->append("converted"); // load textures and stuff gaben = new Texture{data_dir->join("gaben.png")}; auto string_resources = util::read_csv_file<gamedata::string_resource>(asset_dir.join("string_resources.docx")); auto terrain_types = util::read_csv_file<gamedata::terrain_type>(asset_dir.join("gamedata/gamedata-empiresdat/0000-terrains.docx")); auto blending_modes = util::read_csv_file<gamedata::blending_mode>(asset_dir.join("blending_modes.docx")); // create the terrain which will be filled by chunks terrain = new Terrain(assetmanager, terrain_types, blending_modes, true); terrain->fill(terrain_data, terrain_data_size); log::msg("loading game specification files... stand by, will be faster soon..."); util::Dir gamedata_dir = asset_dir.append("gamedata"); auto gamedata = util::recurse_data_files<gamedata::empiresdat>(gamedata_dir, "gamedata-empiresdat.docx"); // create graphic id => graphic map for (auto &graphic : gamedata[0].graphics.data) { this->graphics[graphic.id] = &graphic; } int i = 0; int your_civ_id = 1; //British by default // 0 is gaia and not very useful (it's not an user facing civilization so // we cannot rely on it being polished... it might be VERY broken. // British or any other civ is a way safer bet. log::msg("Using the %s civilisation.", gamedata[0].civs.data[your_civ_id].name.c_str()); for (auto &building : gamedata[0].civs.data[your_civ_id].units.building.data) { log::msg("building[%d]: %s", i, building.name.c_str()); int graphic_id = building.graphic_standing0; if (graphic_id <= 0) { log::msg(" -> ignoring graphics_id: %d", graphic_id); continue; } int slp_id = this->graphics[graphic_id]->slp_id; log::msg(" slp id/name: %d %s", slp_id, this->graphics[graphic_id]->name0.c_str()); if (slp_id <= 0) { log::msg(" -> ignoring slp_id: %d", slp_id); continue; } char *tex_fname = util::format("converted/Data/graphics.drs/%d.slp.png", slp_id); // convert the float to the discrete foundation size... openage::coord::tile_delta foundation_size = { (int)(building.radius_size0 * 2), (int)(building.radius_size1 * 2), }; log::msg(" building has foundation size %.2f x %.2f = %ldx%ld", building.radius_size0, building.radius_size1, foundation_size.ne, foundation_size.se ); int creation_sound = building.sound_creation0; int dying_sound = building.sound_dying; if (creation_sound == -1) { creation_sound = building.sound_creation1; } if (creation_sound == -1) { creation_sound = building.sound_selection; } if (dying_sound == -1) { dying_sound = 323; //generic explosion sound } TestBuilding *newbuilding = new TestBuilding{ this->assetmanager.get_texture(tex_fname), building.name, foundation_size, building.terrain_id, creation_sound, dying_sound }; this->available_buildings.push_back(newbuilding); delete[] tex_fname; i += 1; } // playable sound files for the audio manager std::vector<gamedata::sound_file> sound_files; for (auto &sound : gamedata[0].sounds.data) { for (auto &item : sound.sound_items.data) { char *snd_fname = util::format("Data/sounds.drs/%d.opus", item.resource_id); std::string snd_full_filename = asset_dir.join(snd_fname); if (0 >= util::file_size(snd_full_filename)) { log::msg(" file %s is not there, ignoring...", snd_full_filename.c_str()); delete[] snd_fname; continue; } gamedata::sound_file f { gamedata::audio_category_t::GAME, item.resource_id, snd_fname, gamedata::audio_format_t::OPUS, gamedata::audio_loader_policy_t::IN_MEMORY }; sound_files.push_back(f); delete[] snd_fname; } } // load the requested sounds. audio::AudioManager &am = engine->get_audio_manager(); am.load_resources(asset_dir, sound_files); // create test sound objects that can be played later for (auto &sound : gamedata[0].sounds.data) { std::vector<int> sound_items; for (auto &item : sound.sound_items.data) { sound_items.push_back(item.resource_id); } this->available_sounds[sound.id] = TestSound{sound_items}; } auto player_color_lines = util::read_csv_file<gamedata::palette_color>(asset_dir.join("player_palette_50500.docx")); GLfloat *playercolors = new GLfloat[player_color_lines.size() * 4]; for (size_t i = 0; i < player_color_lines.size(); i++) { auto line = &player_color_lines[i]; playercolors[i*4] = line->r / 255.0; playercolors[i*4 + 1] = line->g / 255.0; playercolors[i*4 + 2] = line->b / 255.0; playercolors[i*4 + 3] = line->a / 255.0; } // shader initialisation // read shader source codes and create shader objects for wrapping them. char *texture_vert_code; util::read_whole_file(&texture_vert_code, data_dir->join("shaders/maptexture.vert.glsl")); auto plaintexture_vert = new shader::Shader(GL_VERTEX_SHADER, texture_vert_code); delete[] texture_vert_code; char *texture_frag_code; util::read_whole_file(&texture_frag_code, data_dir->join("shaders/maptexture.frag.glsl")); auto plaintexture_frag = new shader::Shader(GL_FRAGMENT_SHADER, texture_frag_code); delete[] texture_frag_code; char *teamcolor_frag_code; util::read_whole_file(&teamcolor_frag_code, data_dir->join("shaders/teamcolors.frag.glsl")); auto teamcolor_frag = new shader::Shader(GL_FRAGMENT_SHADER, teamcolor_frag_code); delete[] teamcolor_frag_code; char *alphamask_vert_code; util::read_whole_file(&alphamask_vert_code, data_dir->join("shaders/alphamask.vert.glsl")); auto alphamask_vert = new shader::Shader(GL_VERTEX_SHADER, alphamask_vert_code); delete[] alphamask_vert_code; char *alphamask_frag_code; util::read_whole_file(&alphamask_frag_code, data_dir->join("shaders/alphamask.frag.glsl")); auto alphamask_frag = new shader::Shader(GL_FRAGMENT_SHADER, alphamask_frag_code); delete[] alphamask_frag_code; // create program for rendering simple textures texture_shader::program = new shader::Program(plaintexture_vert, plaintexture_frag); texture_shader::program->link(); texture_shader::texture = texture_shader::program->get_uniform_id("texture"); texture_shader::tex_coord = texture_shader::program->get_attribute_id("tex_coordinates"); texture_shader::program->use(); glUniform1i(texture_shader::texture, 0); texture_shader::program->stopusing(); // create program for tinting textures at alpha-marked pixels // with team colors teamcolor_shader::program = new shader::Program(plaintexture_vert, teamcolor_frag); teamcolor_shader::program->link(); teamcolor_shader::texture = teamcolor_shader::program->get_uniform_id("texture"); teamcolor_shader::tex_coord = teamcolor_shader::program->get_attribute_id("tex_coordinates"); teamcolor_shader::player_id_var = teamcolor_shader::program->get_uniform_id("player_number"); teamcolor_shader::alpha_marker_var = teamcolor_shader::program->get_uniform_id("alpha_marker"); teamcolor_shader::player_color_var = teamcolor_shader::program->get_uniform_id("player_color"); teamcolor_shader::program->use(); glUniform1i(teamcolor_shader::texture, 0); glUniform1f(teamcolor_shader::alpha_marker_var, 254.0/255.0); // fill the teamcolor shader's player color table: glUniform4fv(teamcolor_shader::player_color_var, 64, playercolors); teamcolor_shader::program->stopusing(); delete[] playercolors; // create program for drawing textures that are alpha-masked before alphamask_shader::program = new shader::Program(alphamask_vert, alphamask_frag); alphamask_shader::program->link(); alphamask_shader::base_coord = alphamask_shader::program->get_attribute_id("base_tex_coordinates"); alphamask_shader::mask_coord = alphamask_shader::program->get_attribute_id("mask_tex_coordinates"); alphamask_shader::show_mask = alphamask_shader::program->get_uniform_id("show_mask"); alphamask_shader::base_texture = alphamask_shader::program->get_uniform_id("base_texture"); alphamask_shader::mask_texture = alphamask_shader::program->get_uniform_id("mask_texture"); alphamask_shader::program->use(); glUniform1i(alphamask_shader::base_texture, 0); glUniform1i(alphamask_shader::mask_texture, 1); alphamask_shader::program->stopusing(); // after linking, the shaders are no longer necessary delete plaintexture_vert; delete plaintexture_frag; delete teamcolor_frag; delete alphamask_vert; delete alphamask_frag; }
void Shader::setUniform(const GLchar *name, const glm::float_t& f) { glUniform1f(glGetUniformLocation(p_id, name), f); }
void Program::SetUniformValue(const char* name, const float val) { GLint i = glGetUniformLocation(id, name); if (i != -1) glUniform1f(i, val); }
void IconShader::SetUniformValuef(int uniformLoc, float value) { glUniform1f(uniformLoc, value); }
void a3d_widget_draw(a3d_widget_t* self) { assert(self); LOGD("debug"); if(self->fade == 0.0f) { return; } a3d_rect4f_t rect_border_clip; if(a3d_rect4f_intersect(&self->rect_border, &self->rect_clip, &rect_border_clip) == 0) { return; } // draw the fill a3d_screen_t* screen = self->screen; a3d_vec4f_t* c = &self->color_fill; float alpha = self->fade*c->a; if(alpha > 0.0f) { a3d_screen_scissor(screen, &rect_border_clip); if(alpha < 1.0f) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } a3d_mat4f_t mvp; glBindBuffer(GL_ARRAY_BUFFER, self->id_vtx_rect); a3d_mat4f_ortho(&mvp, 1, 0.0f, screen->w, screen->h, 0.0f, 0.0f, 2.0f); if(self->tone_y2 == 0.0f) { glEnableVertexAttribArray(self->attr_vertex); glVertexAttribPointer(self->attr_vertex, 2, GL_FLOAT, GL_FALSE, 0, 0); glUseProgram(self->prog); glUniform4f(self->unif_color, c->r, c->g, c->b, alpha); glUniformMatrix4fv(self->unif_mvp, 1, GL_FALSE, (GLfloat*) &mvp); } else { a3d_vec4f_t* c2 = &self->color_fill2; float alpha2 = self->fade*c2->a; glEnableVertexAttribArray(self->attr_vertex2); glVertexAttribPointer(self->attr_vertex2, 2, GL_FLOAT, GL_FALSE, 0, 0); glUseProgram(self->prog2); glUniform4f(self->unif_color2a, c->r, c->g, c->b, alpha); glUniform4f(self->unif_color2b, c2->r, c2->g, c2->b, alpha2); glUniform1f(self->unif_y2, self->tone_y2); glUniformMatrix4fv(self->unif_mvp2, 1, GL_FALSE, (GLfloat*) &mvp); } glDrawArrays(GL_TRIANGLE_FAN, 0, 4*A3D_WIDGET_BEZEL); glBindBuffer(GL_ARRAY_BUFFER, 0); if(self->tone_y2 == 0.0f) { glDisableVertexAttribArray(self->attr_vertex); } else { glDisableVertexAttribArray(self->attr_vertex2); } glUseProgram(0); if(alpha < 1.0f) { glDisable(GL_BLEND); } } // draw the contents a3d_rect4f_t rect_draw_clip; if(a3d_rect4f_intersect(&self->rect_draw, &self->rect_clip, &rect_draw_clip)) { a3d_widget_draw_fn draw_fn = self->draw_fn; if(draw_fn) { a3d_screen_scissor(screen, &rect_draw_clip); (*draw_fn)(self); } // draw the scroll bar float s = rect_draw_clip.h/self->rect_draw.h; if(self->scroll_bar && (s < 1.0f)) { // clamp the start/end points float a = -self->drag_dy/self->rect_draw.h; float b = a + s; if(a < 0.0f) { a = 0.0f; } else if(a > 1.0f) { a = 1.0f; } if(b < 0.0f) { b = 0.0f; } else if(b > 1.0f) { b = 1.0f; } a3d_vec4f_t* c0 = &self->color_scroll0; a3d_vec4f_t* c1 = &self->color_scroll1; a3d_screen_scissor(screen, &rect_border_clip); if((c0->a < 1.0f) || (c1->a < 1.0f)) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } a3d_mat4f_t mvp; glBindBuffer(GL_ARRAY_BUFFER, self->scroll_id_vtx_rect); a3d_mat4f_ortho(&mvp, 1, 0.0f, screen->w, screen->h, 0.0f, 0.0f, 2.0f); glEnableVertexAttribArray(self->scroll_attr_vertex); glVertexAttribPointer(self->scroll_attr_vertex, 4, GL_FLOAT, GL_FALSE, 0, 0); glUseProgram(self->scroll_prog); glUniform4f(self->scroll_unif_color0, c0->r, c0->g, c0->b, c0->a); glUniform4f(self->scroll_unif_color1, c1->r, c1->g, c1->b, c1->a); glUniform1f(self->scroll_unif_a, a); glUniform1f(self->scroll_unif_b, b); glUniformMatrix4fv(self->scroll_unif_mvp, 1, GL_FALSE, (GLfloat*) &mvp); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glBindBuffer(GL_ARRAY_BUFFER, 0); glDisableVertexAttribArray(self->scroll_attr_vertex); glUseProgram(0); if((c0->a < 1.0f) || (c1->a < 1.0f)) { glDisable(GL_BLEND); } } } // draw the border c = &self->color_line; alpha = self->fade*c->a; if((alpha > 0.0f) && (self->style_line != A3D_WIDGET_LINE_NONE)) { glDisable(GL_SCISSOR_TEST); if(alpha < 1.0f) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } glUseProgram(self->prog); glEnableVertexAttribArray(self->attr_vertex); // draw rounded line glBindBuffer(GL_ARRAY_BUFFER, self->id_vtx_line); glVertexAttribPointer(self->attr_vertex, 2, GL_FLOAT, GL_FALSE, 0, 0); a3d_mat4f_t mvp; a3d_mat4f_ortho(&mvp, 1, 0.0f, screen->w, screen->h, 0.0f, 0.0f, 2.0f); glUniformMatrix4fv(self->unif_mvp, 1, GL_FALSE, (GLfloat*) &mvp); glUniform4f(self->unif_color, c->r, c->g, c->b, alpha); glDrawArrays(GL_TRIANGLE_STRIP, 0, 2*(4*A3D_WIDGET_BEZEL + 1)); glBindBuffer(GL_ARRAY_BUFFER, 0); glDisableVertexAttribArray(self->attr_vertex); glUseProgram(0); if(alpha < 1.0f) { glDisable(GL_BLEND); } glEnable(GL_SCISSOR_TEST); } }
int main() { glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "ColorTest", nullptr, nullptr); glfwMakeContextCurrent(window); glfwSetKeyCallback(window, key_callback); glfwSetCursorPosCallback(window, mouse_callback); glfwSetScrollCallback(window, scroll_callback); glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); glewExperimental = GL_TRUE; glewInit(); glViewport(0, 0, WIDTH, HEIGHT); glEnable(GL_DEPTH_TEST); //Build and compile shader program Shader lightingShader("../res/texture_map_shaders/texture_map_specular.vs", "../res/texture_map_shaders/texture_map_specular.frag"); Shader lampShader("../res/lamp.vs", "../res/lamp.frag"); // Set up vertex data (and buffer(s)) and attribute pointers GLfloat vertices[] = { // Positions // Normals // Texture Coords -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f, 0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f, 0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f, -0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, -0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, -0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, -0.5f, 0.5f, -0.5f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f, -0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, -0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, -0.5f, -0.5f, 0.5f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, -0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f, 0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f, -0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, -0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f, -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, -0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f }; GLuint VBO, containerVAO; glGenVertexArrays(1, &containerVAO); glGenBuffers(1, &VBO); glBindBuffer(GL_ARRAY_BUFFER, VBO); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); glBindVertexArray(containerVAO); // Position attribute glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)0); glEnableVertexAttribArray(0); // Normal attribute glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat))); glEnableVertexAttribArray(1); //Texture coordinates glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)(6 * sizeof(GLfloat))); glEnableVertexAttribArray(2); glBindVertexArray(0); // Then, we set the light's VAO (VBO stays the same. After all, the vertices are the same for the light object (also a 3D cube)) GLuint lightVAO; glGenVertexArrays(1, &lightVAO); glBindVertexArray(lightVAO); // We only need to bind to the VBO (to link it with glVertexAttribPointer), no need to fill it; the VBO's data already contains all we need. glBindBuffer(GL_ARRAY_BUFFER, VBO); // Set the vertex attributes (only position data for the lamp)) glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)0); // Note that we skip over the normal vectors glEnableVertexAttribArray(0); glBindVertexArray(0); //load textures GLuint diffuseMap, specularMap, emissionMap; glGenTextures(1, &diffuseMap); glGenTextures(1, &specularMap); glGenTextures(1, &emissionMap); int width, height; unsigned char* image; image = SOIL_load_image("../res/images/container2.png", &width, &height, 0, SOIL_LOAD_RGB); glBindTexture(GL_TEXTURE_2D, diffuseMap); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image); glGenerateMipmap(GL_TEXTURE_2D); SOIL_free_image_data(image); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST_MIPMAP_NEAREST); image = SOIL_load_image("../res/images/lighting_maps_specular_color.png", &width, &height, 0, SOIL_LOAD_RGB); glBindTexture(GL_TEXTURE_2D, specularMap); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image); glGenerateMipmap(GL_TEXTURE_2D); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST_MIPMAP_NEAREST); image = SOIL_load_image("../res/images/matrix.jpg", &width, &height, 0, SOIL_LOAD_RGB); glBindTexture(GL_TEXTURE_2D, emissionMap); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image); glGenerateMipmap(GL_TEXTURE_2D); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST_MIPMAP_NEAREST); SOIL_free_image_data(image); glBindTexture(GL_TEXTURE_2D, 0); lightingShader.Use(); GLint materialDiffuseLoc = glGetUniformLocation(lightingShader.Program, "material.diffuse"); GLint materialSpecularLoc = glGetUniformLocation(lightingShader.Program, "material.specular"); GLint materialEmissionLoc = glGetUniformLocation(lightingShader.Program, "material.emission"); glUniform1i(materialDiffuseLoc, 0); glUniform1i(materialSpecularLoc, 1); glUniform1i(materialEmissionLoc, 2); // Game loop while (!glfwWindowShouldClose(window)) { // Calculate deltatime of current frame GLfloat currentFrame = glfwGetTime(); deltaTime = currentFrame - lastFrame; lastFrame = currentFrame; // Check if any events have been activiated (key pressed, mouse moved etc.) and call corresponding response functions glfwPollEvents(); do_movement(); // Clear the colorbuffer glClearColor(0.1f, 0.1f, 0.1f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); lightPos.x = 1.0f + sin(glfwGetTime()) * 2.0f; lightPos.y = sin(glfwGetTime() / 2.0f) * 1.0f; // Use cooresponding shader when setting uniforms/drawing objects lightingShader.Use(); GLint objectColorLoc = glGetUniformLocation(lightingShader.Program, "objectColor"); //GLint lightColorLoc = glGetUniformLocation(lightingShader.Program, "lightColor"); GLint lightPosLoc = glGetUniformLocation(lightingShader.Program, "lightPos"); GLint viewPosLoc = glGetUniformLocation(lightingShader.Program, "viewPos"); glUniform3f(objectColorLoc, 1.0f, 0.5f, 0.31f); //glUniform3f(lightColorLoc, 1.0f, 1.0f, 1.0f); glUniform3f(lightPosLoc, lightPos.x, lightPos.y, lightPos.z); //printf("x:%f, y:%f, z:%f/n", lightPos.x, lightPos.y, lightPos.z); glUniform3f(viewPosLoc, camera.Position.x, camera.Position.y, camera.Position.z); GLint materialShininessLoc = glGetUniformLocation(lightingShader.Program, "material.shininess"); glUniform1f(materialShininessLoc, 32.0f); glm::vec3 lighting; lighting.x = sin(glfwGetTime() * 2.0f); lighting.y = sin(glfwGetTime() * 1.0f); lighting.z = sin(glfwGetTime() * 1.4f); glm::vec3 ambientColor = lighting * glm::vec3(0.2f); glm::vec3 diffuseColor = lighting * glm::vec3(0.6f); GLint lightAmbientLoc = glGetUniformLocation(lightingShader.Program, "light.ambient"); GLint lightDiffuseLoc = glGetUniformLocation(lightingShader.Program, "light.diffuse"); GLint lightSpecularLoc = glGetUniformLocation(lightingShader.Program, "light.specular"); /*glUniform3f(lightAmbientLoc, ambientColor.x, ambientColor.y, ambientColor.z); glUniform3f(lightDiffuseLoc, diffuseColor.x, diffuseColor.y, diffuseColor.z);*/ glUniform3f(lightAmbientLoc, 0.5f, 0.5f, 0.5f); glUniform3f(lightDiffuseLoc, 0.5f, 0.5f, 0.5f); glUniform3f(lightSpecularLoc, 1.0f, 1.0f, 1.0f); // Create camera transformations glm::mat4 view; view = camera.GetViewMatrix(); glm::mat4 projection = glm::perspective(camera.Zoom, (GLfloat)WIDTH / (GLfloat)HEIGHT, 0.1f, 100.0f); // Get the uniform locations GLint modelLoc = glGetUniformLocation(lightingShader.Program, "model"); GLint viewLoc = glGetUniformLocation(lightingShader.Program, "view"); GLint projLoc = glGetUniformLocation(lightingShader.Program, "projection"); // Pass the matrices to the shader glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view)); glUniformMatrix4fv(projLoc, 1, GL_FALSE, glm::value_ptr(projection)); //Bind diffuse map glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, diffuseMap); //Bind specualr map glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, specularMap); //bind emission map glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, emissionMap); // Draw the container (using container's vertex attributes) glBindVertexArray(containerVAO); glm::mat4 model; glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model)); glDrawArrays(GL_TRIANGLES, 0, 36); glBindVertexArray(0); // Also draw the lamp object, again binding the appropriate shader lampShader.Use(); // Get location objects for the matrices on the lamp shader (these could be different on a different shader) modelLoc = glGetUniformLocation(lampShader.Program, "model"); viewLoc = glGetUniformLocation(lampShader.Program, "view"); projLoc = glGetUniformLocation(lampShader.Program, "projection"); // Set matrices glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view)); glUniformMatrix4fv(projLoc, 1, GL_FALSE, glm::value_ptr(projection)); model = glm::mat4(); model = glm::translate(model, lightPos); model = glm::scale(model, glm::vec3(0.2f)); // Make it a smaller cube glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model)); // Draw the light object (using light's vertex attributes) glBindVertexArray(lightVAO); glDrawArrays(GL_TRIANGLES, 0, 36); glBindVertexArray(0); // Swap the screen buffers glfwSwapBuffers(window); } // Terminate GLFW, clearing any resources allocated by GLFW. glfwTerminate(); return 0; }