void CharacterWindow::Draw() const { COORD ulTitleBox = UpperLeft(), brTitleBox = {LowerRight().X,UpperLeft().Y+3}, ulClientBox = {UpperLeft().X,UpperLeft().Y+2}, brClientBox = LowerRight(); COORD titlePosition = {UpperLeft().X+1,UpperLeft().Y+1}; CharacterBox titleBox(ulTitleBox,brTitleBox,BorderColor(),ClientColor(),Fill()) ,clientBox(ulClientBox,brClientBox,BorderColor(),ClientColor(),Fill()); titleBox.Draw(); clientBox.Draw(); if(m_title.size()) ConsoleCore::GetInstance()->Prints(m_title,FALSE,&ClientColor(),titlePosition.X,titlePosition.Y); }
void MultitouchTestBoxWidget::Render() { const Color Colors[] = { Color(static_cast<uint8>(0), 140, 0), Color(static_cast<uint8>(0), 98, 140), Color(static_cast<uint8>(194), 74, 0), Color(static_cast<uint8>(89), 0, 140), Color(static_cast<uint8>(191), 150, 0), Color(static_cast<uint8>(140), 0, 0) }; Color BackgroundColor(Colors[m_Color]); //Color BorderColor(0.0, 0.0, 0.0); Color BorderColor(BackgroundColor); if (CheckHover()) { BorderColor[0] = 0.898; BorderColor[1] = 0.765; BorderColor[2] = 0.396; } DrawBox(GetPosition(), GetDimensions(), BackgroundColor, BorderColor); }
void FunctionWidget::Render() { Color BackgroundColor(1.0, 1.0, 1.0); Color BorderColor(0.3, 0.3, 0.3); /*if (CheckHover(WidgetManager) && CheckActive(WidgetManager)) { } else if ((CheckHover(WidgetManager) && !CheckAnyActive(WidgetManager)) || (!CheckHover(WidgetManager) && CheckActive(WidgetManager))) { BorderColor[0] = 0.898; BorderColor[1] = 0.765; BorderColor[2] = 0.396; } else { }*/ //if (CheckHover()) // HACK if (HasTypingFocus()) { BorderColor[0] = 0.898; BorderColor[1] = 0.765; BorderColor[2] = 0.396; } DrawAroundBox(GetPosition(), GetDimensions(), BackgroundColor, BorderColor); glColor3d(0, 0, 0); OglUtilsPrint(GetPosition().X(), GetPosition().Y() - lineHeight, 0, LEFT, "Global Function"); OpenGLStream OpenGLStream(GetPosition()); OpenGLStream << m_Function; }
bool initSampler() { glGenSamplers(viewport::MAX, &SamplerName[0]); for(std::size_t i = 0; i < viewport::MAX; ++i) { glSamplerParameteri(SamplerName[i], GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glSamplerParameteri(SamplerName[i], GL_TEXTURE_MAG_FILTER, GL_LINEAR); glm::vec4 BorderColor(0.0f, 0.5f, 1.0f, 1.0f); glSamplerParameterfv(SamplerName[i], GL_TEXTURE_BORDER_COLOR, &BorderColor[0]); } glSamplerParameteri(SamplerName[viewport::VIEWPORT0], GL_TEXTURE_WRAP_S, GL_REPEAT); glSamplerParameteri(SamplerName[viewport::VIEWPORT1], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glSamplerParameteri(SamplerName[viewport::VIEWPORT2], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glSamplerParameteri(SamplerName[viewport::VIEWPORT3], GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); glSamplerParameteri(SamplerName[viewport::VIEWPORT4], GL_TEXTURE_WRAP_S, GL_MIRROR_CLAMP_TO_EDGE); if(glf::checkExtension("GL_EXT_texture_mirror_clamp")) glSamplerParameteri(SamplerName[viewport::VIEWPORT5], GL_TEXTURE_WRAP_S, GL_MIRROR_CLAMP_TO_BORDER_EXT); else glSamplerParameteri(SamplerName[viewport::VIEWPORT2], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glSamplerParameteri(SamplerName[viewport::VIEWPORT0], GL_TEXTURE_WRAP_T, GL_REPEAT); glSamplerParameteri(SamplerName[viewport::VIEWPORT1], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glSamplerParameteri(SamplerName[viewport::VIEWPORT2], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glSamplerParameteri(SamplerName[viewport::VIEWPORT3], GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT); glSamplerParameteri(SamplerName[viewport::VIEWPORT4], GL_TEXTURE_WRAP_T, GL_MIRROR_CLAMP_TO_EDGE); if(glf::checkExtension("GL_EXT_texture_mirror_clamp")) glSamplerParameteri(SamplerName[viewport::VIEWPORT5], GL_TEXTURE_WRAP_T, GL_MIRROR_CLAMP_TO_BORDER_EXT); else glSamplerParameteri(SamplerName[viewport::VIEWPORT2], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); return glf::checkError("initSampler"); }
void ButtonWidget::Render() { Color BackgroundColor(0.99, 0.99, 0.99); Color BorderColor(0.5, 0.5, 0.5); if (CheckHover() && CheckActive()) { BackgroundColor[0] = 0.5; BackgroundColor[1] = 0.5; BackgroundColor[2] = 0.5; BorderColor[0] = 0.0; BorderColor[1] = 0.0; BorderColor[2] = 0.0; } //else if ((CheckHover() && !CheckAnyActive()) || (!CheckHover() && CheckActive())) else if (CheckHover() && !CheckActive()) { BackgroundColor[0] = 1.0; BackgroundColor[1] = 1.0; BackgroundColor[2] = 1.0; BorderColor[0] = 0.898; BorderColor[1] = 0.765; BorderColor[2] = 0.396; } else { } DrawBox(GetPosition(), GetDimensions(), BackgroundColor, BorderColor); }
static void SetBorderColor(FXWindow*w) { FXColor c=w->getApp()->getBorderColor(); BorderColor(FXFrame); BorderColor(FXMDIChild); BorderColor(FXPacker); BorderColor(FXPopup); BorderColor(FXScrollBar); BorderColor(FXTable); BorderColor(FXToolBarShell); }
void LabelWidget::Render() { // TODO: Refactor this out if (!m_Visible) return; Color BackgroundColor(1.0, 1.0, 1.0); Color BorderColor(0.6, 0.6, 0.6); auto Content = m_Content(); ModifyDimensions() = Concept::GetDimensions(Content); if (Background::Normal == m_Background) { DrawAroundBox(GetPosition(), GetDimensions(), BackgroundColor, BorderColor); } OpenGLStream OpenGLStream(GetPosition()); OpenGLStream << Content; }
CubeExample(void) : cube( List("Position")("Normal")("TexCoord").Get(), shapes::Cube(), cube_prog ) { // setup the texture { GLuint tex_side = 512; auto image = images::NewtonFractal( tex_side, tex_side, Vec3f(0.2f, 0.1f, 0.4f), Vec3f(0.8f, 0.8f, 1.0f), Vec2f(-1.0f, -1.0f), Vec2f( 1.0f, 1.0f), images::NewtonFractal::X4Minus1(), images::NewtonFractal::DefaultMixer() ); auto bound_tex = Bind(cube_tex, Texture::Target::_2D); bound_tex.Image2D(image); bound_tex.GenerateMipmap(); bound_tex.BorderColor(Vec4f(0.8f, 0.8f, 1.0f, 1.0f)); bound_tex.MinFilter(TextureMinFilter::LinearMipmapLinear); bound_tex.MagFilter(TextureMagFilter::Linear); bound_tex.WrapS(TextureWrap::Repeat); bound_tex.WrapT(TextureWrap::Repeat); } cube_prog.cube_tex = 0; cube_prog.light_position.Set(4.0f, 4.0f, -8.0f); gl.ClearColor(0.8f, 0.8f, 0.7f, 0.0f); gl.ClearDepth(1.0f); gl.Enable(Capability::DepthTest); gl.Enable(Capability::CullFace); gl.CullFace(Face::Back); }
bool initSampler() { glGenSamplers(viewport::MAX, SamplerName); for(std::size_t i = 0; i < viewport::MAX; ++i) { glSamplerParameteri(SamplerName[i], GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glSamplerParameteri(SamplerName[i], GL_TEXTURE_MAG_FILTER, GL_LINEAR); glm::vec4 BorderColor(0.0f, 0.5f, 1.0f, 1.0f); glSamplerParameterfv(SamplerName[i], GL_TEXTURE_BORDER_COLOR, &BorderColor[0]); } glSamplerParameteri(SamplerName[viewport::V00], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glSamplerParameteri(SamplerName[viewport::V10], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glSamplerParameteri(SamplerName[viewport::V11], GL_TEXTURE_WRAP_S, GL_REPEAT); glSamplerParameteri(SamplerName[viewport::V01], GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); glSamplerParameteri(SamplerName[viewport::V00], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glSamplerParameteri(SamplerName[viewport::V10], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glSamplerParameteri(SamplerName[viewport::V11], GL_TEXTURE_WRAP_T, GL_REPEAT); glSamplerParameteri(SamplerName[viewport::V01], GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT); return glf::checkError("initSampler"); }
template <typename T> void ListWidget<T>::Render() { Color BackgroundColor(1.0, 1.0, 1.0); Color BorderColor(0.3, 0.3, 0.3); /*if (CheckHover(WidgetManager) && CheckActive(WidgetManager)) { } else if ((CheckHover(WidgetManager) && !CheckAnyActive(WidgetManager)) || (!CheckHover(WidgetManager) && CheckActive(WidgetManager))) { BorderColor[0] = 0.898; BorderColor[1] = 0.765; BorderColor[2] = 0.396; } else { }*/ // TODO: Think if I should outsource the entire rendering code for more generality // Draw list { UpdateDimensions(); // LATER: Optimize by not repeating this calculation each time, only when something changes? if (m_List.empty()) { BackgroundColor[0] = 234 / 255.0; BackgroundColor[1] = 233 / 255.0; BackgroundColor[2] = 190 / 255.0; } DrawAroundBox(GetPosition(), GetDimensions(), BackgroundColor, BorderColor); // TODO: This part is not general std::string Description[2] = { "#include <", ">" }; glColor3d(0, 0, 0); OglUtilsPrint(GetPosition().X(), GetPosition().Y(), 0, RIGHT, Description[0].c_str()); glColor3d(0, 0, 0); OglUtilsPrint(GetPosition().X() + GetDimensions().X(), GetPosition().Y(), 0, LEFT, Description[1].c_str()); // TEST auto Spot = m_List.end(); if (!m_TypingModule.GetString().empty()) { for (auto & Pointer : GetGestureRecognizer().GetConnected()) { if (Pointer::VirtualCategory::POINTING == Pointer->GetVirtualCategory()) { Vector2n GlobalPosition(Pointer->GetPointerState().GetAxisState(0).GetPosition(), Pointer->GetPointerState().GetAxisState(1).GetPosition()); Vector2n LocalPosition(GlobalToLocal(GlobalPosition)); Spot = m_List.begin() + (LocalPosition.Y() / lineHeight); } } } OpenGLStream OpenGLStream(GetPosition()); for (auto ListEntry = m_List.begin(); m_List.end() != ListEntry; ++ListEntry) { if (ListEntry == Spot) OpenGLStream << endl; OpenGLStream << *ListEntry << endl; } } CompositeWidget::Render(); }
void ConceptStringBoxWidget::Render() { Color BackgroundColor(1.0, 1.0, 1.0); Color BorderColor(0.3, 0.3, 0.3); /*if (CheckHover(WidgetManager) && CheckActive(WidgetManager)) { } else if ((CheckHover(WidgetManager) && !CheckAnyActive(WidgetManager)) || (!CheckHover(WidgetManager) && CheckActive(WidgetManager))) { BorderColor[0] = 0.898; BorderColor[1] = 0.765; BorderColor[2] = 0.396; } else { }*/ //if (CheckHover()) // HACK if (HasTypingFocus()) { BorderColor[0] = 0.898; BorderColor[1] = 0.765; BorderColor[2] = 0.396; } /*glBegin(GL_QUADS); glVertex2d(m_Position.X(), m_Position.Y()); glVertex2d(m_Position.X(), m_Position.Y() + 30); glVertex2d(m_Position.X() + 30, m_Position.Y() + 30); glVertex2d(m_Position.X() + 30, m_Position.Y()); glEnd();*/ DrawAroundBox(GetPosition(), GetDimensions(), BackgroundColor, BorderColor); glColor3d(0, 0, 0); OpenGLStream OpenGLStream(GetPosition()); //OpenGLStream << m_Content.substr(0, m_CaretPosition); // TODO: Optimize this somehow? OpenGLStream << decltype(m_Content)(m_Content.begin(), m_Content.begin() + m_CaretPosition); // TEST if (!m_TypingModule.GetString().empty()) { for (auto & Pointer : GetGestureRecognizer().GetConnected()) { if (Pointer::VirtualCategory::POINTING == Pointer->GetVirtualCategory()) { //Vector2n GlobalPosition(Pointer->GetPointerState().GetAxisState(0).GetPosition(), Pointer->GetPointerState().GetAxisState(1).GetPosition()); //Vector2n LocalPosition(GlobalToLocal(GlobalPosition)); //auto ConceptId = FindOrCreateConcept(Entry); OpenGLStream << m_TypingModule.GetString(); } } } Vector2n CaretPosition = OpenGLStream.GetCaretPosition(); //OpenGLStream << m_Content.substr(m_CaretPosition); // TODO: Optimize this somehow? OpenGLStream << decltype(m_Content)(m_Content.begin() + m_CaretPosition, m_Content.end()); //if (CheckHover()) // HACK if (HasTypingFocus()) { // Draw caret //if (static_cast<int>(glfwGetTime() * 2) % 2) { glPushMatrix(); glTranslated(CaretPosition.X(), CaretPosition.Y(), 0); glColor3d(0, 0, 0); glBegin(GL_QUADS); glVertex2d(-1, 0); glVertex2d(-1, lineHeight); glVertex2d(+1, lineHeight); glVertex2d(+1, 0); glEnd(); glPopMatrix(); } } }
template <typename T> void MenuWidget<T>::Render() { Color BackgroundColor(1.0, 1.0, 1.0); Color BorderColor(0.3, 0.3, 0.3); /*if (CheckHover(WidgetManager) && CheckActive(WidgetManager)) { } else if ((CheckHover(WidgetManager) && !CheckAnyActive(WidgetManager)) || (!CheckHover(WidgetManager) && CheckActive(WidgetManager))) { BorderColor[0] = 0.898; BorderColor[1] = 0.765; BorderColor[2] = 0.396; } else { }*/ // HACK, TODO: Make this a single DRY const if (HasTypingFocus()) { BorderColor[0] = 0.898; BorderColor[1] = 0.765; BorderColor[2] = 0.396; } // TODO: Think if I should outsource the entire rendering code for more generality // Draw list { UpdateDimensions(); // LATER: Optimize by not repeating this calculation each time, only when something changes? if (m_Entries.empty()) { BackgroundColor[0] = 234 / 255.0; BackgroundColor[1] = 233 / 255.0; BackgroundColor[2] = 190 / 255.0; } DrawAroundBox(GetPosition(), GetDimensions(), BackgroundColor, BorderColor); // TEST auto Spot = m_Entries.end(); if ( nullptr != m_TypingModule && !m_TypingModule->GetString().empty()) { for (auto & Pointer : GetGestureRecognizer().GetConnected()) { if (Pointer::VirtualCategory::POINTING == Pointer->GetVirtualCategory()) { Vector2n GlobalPosition(Pointer->GetPointerState().GetAxisState(0).GetPosition(), Pointer->GetPointerState().GetAxisState(1).GetPosition()); Vector2n LocalPosition(GlobalToLocal(GlobalPosition)); Spot = m_Entries.begin() + (LocalPosition.Y() / lineHeight); } } } OpenGLStream OpenGLStream(GetPosition()); //for (auto & Entry : m_Entries) for (auto Entry = m_Entries.begin(); m_Entries.end() != Entry; ++Entry) { if (Entry == Spot) OpenGLStream << endl; if (Entry - m_Entries.begin() == m_SelectedEntryId) { if (HasTypingFocus()) DrawBox(GetPosition() + Vector2n(0, static_cast<sint32>((Entry - m_Entries.begin() + (Entry >= Spot)) * lineHeight)), Vector2n(GetDimensions().X(), lineHeight), m_SelectedColor, m_SelectedColor); else DrawBox(GetPosition() + Vector2n(0, static_cast<sint32>((Entry - m_Entries.begin() + (Entry >= Spot)) * lineHeight)), Vector2n(GetDimensions().X(), lineHeight), m_UnfocusedSelectedColor, m_UnfocusedSelectedColor); } OpenGLStream << *Entry << endl; } } }
SmokeExample(void) : emitters( { { { {-20.0f, -10.0f, 10.0f}, { 20.0f, 0.0f, -20.0f}, { 20.0f, 10.0f, 20.0f}, {-20.0f, 0.0f, -10.0f} }, 15.0, 200.0 }, { { { 30.0f, 0.0f, 5.0f}, {-30.0f, 0.0f, -5.0f}, {-20.0f, 20.0f, 5.0f}, { 20.0f, -10.0f, -5.0f} }, 17.0, 200.0 }, } ), vs(ShaderType::Vertex, "Vertex") , gs(ShaderType::Geometry, "Geometry") , fs(ShaderType::Fragment, "Fragment") , projection_matrix(prog, "ProjectionMatrix") , camera_matrix(prog, "CameraMatrix") , light_cam_pos(prog, "LightCamPos") { // Set the vertex shader source vs.Source( "#version 330\n" "uniform mat4 CameraMatrix;" "in vec4 Position;" "in float Age;" "in int Id;" "out float vertAge;" "out int vertId;" "void main(void)" "{" " gl_Position = CameraMatrix * Position;" " vertAge = Age;" " vertId = Id;" "}" ); // compile it vs.Compile(); // Set the geometry shader source gs.Source( "#version 330\n" "layout(points) in;" "layout(triangle_strip, max_vertices = 4) out;" "uniform vec3 LightCamPos;" "uniform mat4 ProjectionMatrix;" "in float vertAge[];" "in int vertId[];" "out vec2 geomTexCoord;" "out float geomAge;" "out float geomLightVal;" "out float geomLightBias;" "void main(void)" "{" " if(vertAge[0] > 1.0) return;" " vec3 pos = gl_in[0].gl_Position.xyz;" " vec3 lightDir = normalize(LightCamPos - pos);" " float s = 0.8, g = 3.0;" " float yo[2] = float[2](-1.0, 1.0);" " float xo[2] = float[2](-1.0, 1.0);" " float angle = vertId[0];" " float cx = cos(angle), sx = sin(angle);" " mat2 rot = mat2(cx, sx, -sx, cx);" " for(int j=0;j!=2;++j)" " for(int i=0;i!=2;++i)" " {" " float xoffs = xo[i]*(1.0+vertAge[0]*g)*s;" " float yoffs = yo[j]*(1.0+vertAge[0]*g)*s;" " vec2 offs = rot*vec2(xoffs, yoffs);" " gl_Position = ProjectionMatrix * vec4(" " pos.x-offs.x," " pos.y-offs.y," " pos.z," " 1.0" " );" " geomTexCoord = vec2(float(i), float(j));" " geomAge = vertAge[0];" " geomLightVal = lightDir.z;" " geomLightBias = -dot(" " normalize(vec3(offs, 0.0))," " lightDir" " );" " EmitVertex();" " }" " EndPrimitive();" "}" ); // compile it gs.Compile(); // set the fragment shader source fs.Source( "#version 330\n" "uniform sampler2D SmokeTex;" "in vec2 geomTexCoord;" "in float geomAge;" "in float geomLightVal;" "in float geomLightBias;" "out vec4 fragColor;" "void main(void)" "{" " vec3 c = texture(SmokeTex, geomTexCoord).rgb;" " float depth = c.g - c.r;" " if(depth == 0.0) discard;" " float density = min(depth * c.b * 2.0, 1.0);" " float intensity = min(" " max(" " geomLightVal*0.5+" " geomLightBias," " 0.0" " )+max(" " -geomLightVal*" " (1.0 - density)*" " geomLightBias * 5.0," " 0.0" " )," " 1.0" " ) + 0.1;" " fragColor = vec4(" " intensity," " intensity," " intensity," " (1.0 - geomAge)*density" " );" "}" ); // compile it fs.Compile(); // attach the shaders to the program prog.AttachShader(vs); prog.AttachShader(gs); prog.AttachShader(fs); // link and use it prog.Link(); prog.Use(); // bind the VAO for the particles particles.Bind(); // bind the VBO for the particle positions pos_buf.Bind(Buffer::Target::Array); { Buffer::Data(Buffer::Target::Array, positions); VertexAttribArray attr(prog, "Position"); attr.Setup<Vec3f>(); attr.Enable(); } // bind the VBO for the particle ages age_buf.Bind(Buffer::Target::Array); { Buffer::Data(Buffer::Target::Array, ages); VertexAttribArray attr(prog, "Age"); attr.Setup<GLfloat>(); attr.Enable(); } // bind the VBO for the particle identifiers id_buf.Bind(Buffer::Target::Array); { Buffer::Data(Buffer::Target::Array, ids); VertexAttribArray attr(prog, "Id"); attr.Setup<GLint>(); attr.Enable(); } Texture::Active(0); UniformSampler(prog, "SmokeTex").Set(0); { auto bound_tex = Bind(smoke_tex, Texture::Target::_2D); bound_tex.Image2D( images::Cloud2D( images::Cloud( 128, 128, 128, Vec3f(0.1f, -0.5f, 0.3f), 0.5f ) ) ); bound_tex.GenerateMipmap(); bound_tex.MinFilter(TextureMinFilter::LinearMipmapLinear); bound_tex.MagFilter(TextureMagFilter::Linear); bound_tex.BorderColor(Vec4f(0.0f, 0.0f, 0.0f, 0.0f)); bound_tex.WrapS(TextureWrap::ClampToBorder); bound_tex.WrapT(TextureWrap::ClampToBorder); } // gl.ClearColor(0.0f, 0.1f, 0.2f, 0.0f); gl.ClearDepth(1.0f); gl.Enable(Capability::DepthTest); gl.Enable(Capability::Blend); gl.BlendFunc(BlendFn::SrcAlpha, BlendFn::OneMinusSrcAlpha); }
template <typename T> void ListWidget<T>::Render() { Color BackgroundColor(1.0, 1.0, 1.0); Color BorderColor(0.3, 0.3, 0.3); /*if (CheckHover(WidgetManager) && CheckActive(WidgetManager)) { } else if ((CheckHover(WidgetManager) && !CheckAnyActive(WidgetManager)) || (!CheckHover(WidgetManager) && CheckActive(WidgetManager))) { BorderColor[0] = 0.898; BorderColor[1] = 0.765; BorderColor[2] = 0.396; } else { }*/ // TODO: Think if I should outsource the entire rendering code for more generality // Draw list { UpdateDimensions(); // LATER: Optimize by not repeating this calculation each time, only when something changes? if (m_Entries.empty()) { BackgroundColor[0] = 234 / 255.0; BackgroundColor[1] = 233 / 255.0; BackgroundColor[2] = 190 / 255.0; } DrawAroundBox(GetPosition(), GetDimensions(), BackgroundColor, BorderColor); // TEST auto Spot = m_Entries.end(); if (!m_TypingModule.GetString().empty()) { for (auto & Pointer : GetGestureRecognizer().GetConnected()) { if (Pointer::VirtualCategory::POINTING == Pointer->GetVirtualCategory()) { Vector2n GlobalPosition(Pointer->GetPointerState().GetAxisState(0).GetPosition(), Pointer->GetPointerState().GetAxisState(1).GetPosition()); Vector2n LocalPosition(GlobalToLocal(GlobalPosition)); Spot = m_Entries.begin() + (LocalPosition.Y() / lineHeight); } } } OpenGLStream OpenGLStream(GetPosition()); for (auto Entry = m_Entries.begin(); m_Entries.end() != Entry; ++Entry) { if (Entry == Spot) OpenGLStream << endl; OpenGLStream << *Entry << endl; } } #if DECISION_LIST_WIDGET_IS_COMPOSITE CompositeWidget::Render(); #endif }
CloudExample(void) : projection_matrix(prog, "ProjectionMatrix") , camera_matrix(prog, "CameraMatrix") { // Set the vertex shader source vs.Source( "#version 330\n" "in vec4 Position;" "uniform mat4 CameraMatrix;" "void main(void)" "{" " gl_Position = " " CameraMatrix *" " Position;" "}" ); // compile it vs.Compile(); // Set the geometry shader source gs.Source( "#version 330\n" "layout(points) in;" "layout(triangle_strip, max_vertices = 100) out;" "const int p = 25;" "const float hp = (p-1)*0.5;" "uniform vec3 LightPos;" "uniform mat4 CameraMatrix, ProjectionMatrix;" "out vec3 geomTexCoord;" "out vec3 geomLightDir;" "void main(void)" "{" " float s = 0.6;" " float yo[2] = float[2](-1.0, 1.0);" " float xo[2] = float[2](-1.0, 1.0);" " vec3 cx = vec3(" " CameraMatrix[0][0]," " CameraMatrix[1][0]," " CameraMatrix[2][0] " " );" " vec3 cy = vec3(" " CameraMatrix[0][1]," " CameraMatrix[1][1]," " CameraMatrix[2][1] " " );" " vec3 cz = vec3(" " CameraMatrix[0][2]," " CameraMatrix[1][2]," " CameraMatrix[2][2] " " );" " for(int k=0;k!=p;++k)" " {" " for(int j=0;j!=2;++j)" " for(int i=0;i!=2;++i)" " {" " float zo = ((k - hp) / hp);" " float xoffs = xo[i]*s;" " float yoffs = yo[j]*s;" " float zoffs = zo *s;" " vec4 v = vec4(" " gl_in[0].gl_Position.x+xoffs," " gl_in[0].gl_Position.y+yoffs," " gl_in[0].gl_Position.z+zoffs," " 1.0" " );" " gl_Position = ProjectionMatrix * v;" " geomLightDir = LightPos - v.xyz;" " geomTexCoord = " " vec3(0.5, 0.5, 0.5)+" " cx*(xo[i])*0.707+" " cy*(yo[j])*0.707+" " cz*(zo )*0.707;" " EmitVertex();" " }" " EndPrimitive();" " }" "}" ); // compile it gs.Compile(); // set the fragment shader source fs.Source( "#version 330\n" "uniform sampler3D cloudTex;" "in vec3 geomTexCoord;" "in vec3 geomLightDir;" "out vec4 fragColor;" "void main(void)" "{" " float d = texture(cloudTex, geomTexCoord).r;" " float o = 1.0;" " float s = 2.0/128.0;" " float r = s * 8.0;" " vec3 sampleOffs = normalize(geomLightDir) * s;" " vec3 samplePos = geomTexCoord;" " if(d > 0.01) while(o > 0.0)" " {" " if(samplePos.x<0.0 || samplePos.x>1.0)" " break;" " if(samplePos.y<0.0 || samplePos.y>1.0)" " break;" " if(samplePos.z<0.0 || samplePos.z>1.0)" " break;" " o -= texture(cloudTex, samplePos).r*r;" " samplePos += sampleOffs;" " }" " float a = 0.2 * d;" " float i = mix(0.4, 1.0, o);" " fragColor = vec4(i, i, i, a);" "}" ); // compile it fs.Compile(); // attach the shaders to the program prog.AttachShader(vs); prog.AttachShader(gs); prog.AttachShader(fs); // link and use it prog.Link(); prog.Use(); // bind the VAO for the clouds clouds.Bind(); // bind the VBO for the cloud positions buffer.Bind(Buffer::Target::Array); { GLfloat positions[3] = {0.5f, 0.1f, 0.2f}; Buffer::Data(Buffer::Target::Array, 3, positions); VertexAttribArray attr(prog, "Position"); attr.Setup(3, DataType::Float); attr.Enable(); } { Texture::Active(0); UniformSampler(prog, "cloudTex").Set(0); auto bound_tex = Bind(cloud_tex, Texture::Target::_3D); bound_tex.Image3D(images::Cloud(128, 128, 128)); bound_tex.GenerateMipmap(); bound_tex.MinFilter(TextureMinFilter::LinearMipmapLinear); bound_tex.MagFilter(TextureMagFilter::Linear); bound_tex.BorderColor(Vec4f(0.0f, 0.0f, 0.0f, 0.0f)); bound_tex.WrapS(TextureWrap::ClampToBorder); bound_tex.WrapT(TextureWrap::ClampToBorder); bound_tex.WrapR(TextureWrap::ClampToBorder); } Uniform<Vec3f>(prog, "LightPos").Set(Vec3f(10.0f, 1.0f, 5.0f)); gl.ClearColor(0.2f, 0.3f, 0.4f, 0.0f); gl.ClearDepth(1.0f); gl.Enable(Capability::DepthTest); gl.Enable(Capability::Blend); gl.BlendFunc(BlendFn::SrcAlpha, BlendFn::OneMinusSrcAlpha); }
CloudExample(const ExampleParams& params) : sphere_instr(make_sphere.Instructions()) , sphere_indices(make_sphere.Indices()) , samples(25 + params.quality*params.quality*100) , positions(make_positions()) , sizes(make_sizes()) , cloud_tex(positions.size()) , light_path(make_light_path_cps()) { assert(positions.size() == sizes.size()); std::srand(123456); light_vs.Source( "#version 330\n" "in vec3 Position;" "uniform vec3 LightPos;" "uniform mat4 CameraMatrix, ProjectionMatrix;" "void main(void)" "{" " float s = 0.1;" " gl_Position = " " ProjectionMatrix*" " CameraMatrix*" " vec4(Position*s + LightPos, 1.0);" "}" ).Compile(); light_fs.Source( "#version 330\n" "out vec4 fragLight;" "void main(void)" "{" " fragLight = vec4(1.0, 1.0, 1.0, 1.0);" "}" ).Compile(); light_prog << light_vs << light_fs; light_prog.Link().Use(); light.Bind(); buffer.Bind(Buffer::Target::Array); { std::vector<GLfloat> data; GLuint n_per_vertex = make_sphere.Positions(data); Buffer::Data(Buffer::Target::Array, data); (light_prog|"Position").Setup(n_per_vertex, DataType::Float).Enable(); } cloud_vs.Source( "#version 330\n" "in vec4 Position;" "in float Size;" "uniform int SampleCount;" "uniform mat4 CameraMatrix;" "uniform vec4 ViewZ;" "out float vertZOffs;" "out float vertSize;" "void main(void)" "{" " float hp = (SampleCount-1) * 0.5;" " vertZOffs = (gl_InstanceID - hp)/hp;" " vertSize = Size;" " gl_Position = vec4(" " Position.xyz +" " ViewZ.xyz*vertZOffs*Size*0.5," " 1.0" " );" "}" ).Compile(); cloud_gs.Source( "#version 330\n" "layout(points) in;" "layout(triangle_strip, max_vertices = 4) out;" "in float vertZOffs[];" "in float vertSize[];" "uniform vec3 LightPos;" "uniform mat4 CameraMatrix, ProjectionMatrix;" "uniform vec4 ViewX, ViewY, ViewZ;" "out vec3 geomTexCoord;" "out vec3 geomLightDir;" "void main(void)" "{" " float zo = vertZOffs[0];" " float s = vertSize[0];" " float yo[2] = float[2](-1.0, 1.0);" " float xo[2] = float[2](-1.0, 1.0);" " for(int j=0;j!=2;++j)" " for(int i=0;i!=2;++i)" " {" " vec4 v = vec4(" " gl_in[0].gl_Position.xyz+" " ViewX.xyz * xo[i] * s * 0.5+" " ViewY.xyz * yo[j] * s * 0.5," " 1.0" " );" " gl_Position = ProjectionMatrix * CameraMatrix * v;" " geomLightDir = LightPos - v.xyz;" " geomTexCoord = " " vec3(0.5, 0.5, 0.5)+" " ViewX.xyz*(xo[i])*0.707+" " ViewY.xyz*(yo[j])*0.707+" " ViewZ.xyz*(zo )*0.707;" " EmitVertex();" " }" " EndPrimitive();" "}" ).Compile(); cloud_fs.Source( "#version 330\n" "uniform sampler3D CloudTex;" "in vec3 geomTexCoord;" "in vec3 geomLightDir;" "out vec4 fragColor;" "void main(void)" "{" " float d = texture(CloudTex, geomTexCoord).r;" " float o = 1.0;" " float s = 2.0/128.0;" " float r = s * 8.0;" " vec3 sampleOffs = normalize(geomLightDir) * s;" " vec3 samplePos = geomTexCoord;" " if(d > 0.01) while(o > 0.0)" " {" " if(samplePos.x<0.0 || samplePos.x>1.0)" " break;" " if(samplePos.y<0.0 || samplePos.y>1.0)" " break;" " if(samplePos.z<0.0 || samplePos.z>1.0)" " break;" " o -= texture(CloudTex, samplePos).r*r;" " samplePos += sampleOffs;" " }" " float a = 0.4 * d;" " float i = mix(0.2, 1.0, o);" " fragColor = vec4(i, i, i, a);" "}" ).Compile(); cloud_prog << cloud_vs << cloud_gs << cloud_fs; cloud_prog.Link().Use(); // bind the VAO for the clouds clouds.Bind(); // bind the VBO for the cloud positions pos_buffer.Bind(Buffer::Target::Array); { Buffer::Data(Buffer::Target::Array, positions); (cloud_prog|"Position").Setup(3, DataType::Float).Enable(); } // bind the VBO for the cloud sizes size_buffer.Bind(Buffer::Target::Array); { Buffer::Data(Buffer::Target::Array, sizes); (cloud_prog|"Size").Setup(1, DataType::Float).Enable(); } // set the number of samples cloud_prog/"SampleCount" = GLint(samples); Texture::Active(0); cloud_prog/"CloudTex" = 0; for(std::size_t i=0, n=positions.size(); i!=n; ++i) { auto bound_tex = Bind(cloud_tex[i], Texture::Target::_3D); bound_tex.Image3D( images::Cloud( 128, 128, 128, Vec3f(0.1f, -0.5f, 0.3f), 0.5f ) ); bound_tex.GenerateMipmap(); bound_tex.MinFilter(TextureMinFilter::LinearMipmapLinear); bound_tex.MagFilter(TextureMagFilter::Linear); bound_tex.BorderColor(Vec4f(0.0f, 0.0f, 0.0f, 0.0f)); bound_tex.WrapS(TextureWrap::ClampToBorder); bound_tex.WrapT(TextureWrap::ClampToBorder); bound_tex.WrapR(TextureWrap::ClampToBorder); } gl.ClearColor(0.0f, 0.1f, 0.2f, 0.0f); gl.ClearDepth(1.0f); gl.Disable(Capability::DepthTest); gl.Enable(Capability::Blend); gl.BlendFunc(BlendFn::SrcAlpha, BlendFn::OneMinusSrcAlpha); }
void TextFieldWidget::Render() { //Color BackgroundColor(1.0, 1.0, 1.0); Color BackgroundColor = m_BackgroundColor; Color BorderColor(0.3, 0.3, 0.3); /*if (CheckHover(WidgetManager) && CheckActive(WidgetManager)) { } else if ((CheckHover(WidgetManager) && !CheckAnyActive(WidgetManager)) || (!CheckHover(WidgetManager) && CheckActive(WidgetManager))) { BorderColor[0] = 0.898; BorderColor[1] = 0.765; BorderColor[2] = 0.396; } else { }*/ //if (CheckHover()) // HACK if (HasTypingFocus()) { BorderColor[0] = 0.898; BorderColor[1] = 0.765; BorderColor[2] = 0.396; } /*glBegin(GL_QUADS); glVertex2d(m_Position.X(), m_Position.Y()); glVertex2d(m_Position.X(), m_Position.Y() + 30); glVertex2d(m_Position.X() + 30, m_Position.Y() + 30); glVertex2d(m_Position.X() + 30, m_Position.Y()); glEnd();*/ DrawAroundBox(GetPosition(), GetDimensions(), BackgroundColor, BorderColor); // TEST auto ContentWithInsertion = m_Content; if (!m_TypingModule.GetString().empty()) { for (auto & Pointer : GetGestureRecognizer().GetConnected()) { if (Pointer::VirtualCategory::POINTING == Pointer->GetVirtualCategory()) { Vector2n GlobalPosition(Pointer->GetPointerState().GetAxisState(0).GetPosition(), Pointer->GetPointerState().GetAxisState(1).GetPosition()); Vector2n LocalPosition(GlobalToLocal(GlobalPosition)); LocalPosition = m_TypingModule.GetInsertionPosition(LocalPosition); auto InsertionPosition = GetNearestCaretPosition(LocalPosition); ContentWithInsertion.insert(InsertionPosition, m_TypingModule.GetString()); } } } glColor3d(0, 0, 0); OpenGLStream OpenGLStream(GetPosition()); OpenGLStream << ContentWithInsertion.substr(0, std::min(m_CaretPosition, m_SelectionPosition)); Vector2n CaretPosition; // Remember caret position at selection front if (std::min(m_CaretPosition, m_SelectionPosition) == m_CaretPosition) { CaretPosition = OpenGLStream.GetCaretPosition(); } // Draw selected text as highlighted if (HasTypingFocus()) { OpenGLStream.SetBackgroundColor(Color(static_cast<uint8>(195), 212, 242)); } else { OpenGLStream.SetBackgroundColor(Color(static_cast<uint8>(212), 212, 212)); } auto SelectionLength = std::max(m_CaretPosition, m_SelectionPosition) - std::min(m_CaretPosition, m_SelectionPosition); OpenGLStream << ContentWithInsertion.substr(std::min(m_CaretPosition, m_SelectionPosition), SelectionLength); OpenGLStream.SetBackgroundColor(Color(1.0, 1.0, 1.0)); // Remember caret position at selection back if (std::max(m_CaretPosition, m_SelectionPosition) == m_CaretPosition) { CaretPosition = OpenGLStream.GetCaretPosition(); } OpenGLStream << ContentWithInsertion.substr(std::max(m_CaretPosition, m_SelectionPosition)); //if (CheckHover()) // HACK if (HasTypingFocus()) { // Draw caret //if (static_cast<int>(glfwGetTime() * 2) % 2) { glPushMatrix(); glTranslated(CaretPosition.X(), CaretPosition.Y(), 0); glColor3d(0, 0, 0); glBegin(GL_QUADS); glVertex2d(-1, 0); glVertex2d(-1, lineHeight); glVertex2d(+1, lineHeight); glVertex2d(+1, 0); glEnd(); glPopMatrix(); } } }