-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use advance opengl 3.0 inaccurate display #1273
Comments
The first image is generator from the problem code.. |
My idea is that even with advanced opengl, the material of the model can still be obtained from the OSG file normally, and the model can be rendered in the shader through built-in OSG variables. Is this idea feasible? |
The result seems to be correct. The shader code you provided uses diffuse lighting as the fragment color. And the image shows the same thing. |
How can I reference the model colors set in the OSG file in the shader? I tried using osg_ Color is still invalid in the shader. Thank you! |
If want want to use advanced graphics functionality then OpenGL/OpenSceneGraph isn't the best tool. You will likely find it easier to using modern APIs like Vulkan/VulkanSceneGraph. |
Yes, but I currently want to quickly implement something similar to Google Earth. After searching for some information, I learned that OSG and OSgEarth can quickly help me achieve it, so I am currently trying to understand OSG |
I think my current problem is that after reading the OSG file, I cannot easily extract the colors specified in the file and use them in the shader. |
The VulkanSceneGraph README.md provides links to a number of related projects including vsgQt: https://github.com/vsg-dev/VulkanSceneGraph vsgQt itself: |
osg_Color should work as an alternative of gl_Color. Make sure it's vec4 |
Thank you! This plan is feasible. Where can I find any built-in opengl variables for OSG? |
For example, textures |
OSG replaces gl_* attributes for convience under core profile. Have a look at State::resetVertexAttributeAlias(): And some necessary uniforms, at State::convertVertexShaderSourceToOsgBuiltIns(): FYI, don't forget those uniforms that work under both core and compatible profiles. See them at SceneView::updateUniforms(): |
Thank you! I found it. |
Thank you! |
Now I want to use advanced opengl in 3.7.0, but there are some issues. After running the example, the model did not display correctly. Is there a problem with my code? I enable advanced opengl attributes when compiling the source code.
#include <osgViewer/Viewer>
#include <osgDB/ReadFile>
#include <osg/GraphicsContext>
#include <osg/Camera>
#include <osg/Viewport>
#include <osg/StateSet>
#include <osg/Program>
#include <osg/Shader>
#include <osgUtil/Optimizer>
#include <osgGA/StateSetManipulator>
#include <osgGA/TrackballManipulator>
#include <osgGA/FlightManipulator>
#include <osgGA/KeySwitchMatrixManipulator>
#include <osgGA/AnimationPathManipulator>
#include <osgGA/TerrainManipulator>
#include <osgGA/DriveManipulator>
#include <osgViewer/ViewerEventHandlers>
void configureShaders(osg::StateSet* stateSet)
{
const std::string vertexSource =
"#version 130 \n"
" \n"
"uniform mat4 osg_ModelViewProjectionMatrix; \n"
"uniform mat3 osg_NormalMatrix; \n"
"uniform vec3 ecLightDir; \n"
" \n"
"in vec4 osg_Vertex; \n"
"in vec3 osg_Normal; \n"
"out vec4 color; \n"
" \n"
"void main() \n"
"{ \n"
" vec3 ecNormal = normalize( osg_NormalMatrix * osg_Normal ); \n"
" float diffuse = max( dot( ecLightDir, ecNormal ), 0. ); \n"
" color = vec4( vec3( diffuse ), 1. ); \n"
" \n"
" gl_Position = osg_ModelViewProjectionMatrix * osg_Vertex; \n"
"} \n";
osg::Shader* vShader = new osg::Shader(osg::Shader::VERTEX, vertexSource);
}
int main(int argc, char** argv)
{
std::vectorstd::string fileList;
fileList.push_back("glider.osg");
// 创建节点.
osg::ref_ptrosg::Node root = osgDB::readRefNodeFiles(fileList);
if (root == NULL)
{
osg::notify(osg::FATAL) << "Unable to load model from command line." << std::endl;
return(1);
}
}
The text was updated successfully, but these errors were encountered: