OSG passed the coloring tool variable

Source: Internet
Author: User
> I tried using a different attribute index from 0, and the colours are now showing up. I had come into ss the link earlier that you posted, but didn't realize that was how OpenGL worked (I tested it out in an OpenGL app and got the same problem as in my OSG app, with the slightly deformed mesh and no colours ).
>
> So if I use custom attributes and no built in ones, then I shouldn't have this problem of overwriting existing attributes, which I also tested in the OpenGL app, and it allowed me to use 0 for a vertex attrib, and 1 for a color attrib. so that's what I want to do now in my OSG app. but I cannot get it to work, it just renders nothing. I have tried different attribute values (from '0 and 1', '10 and 11', to '0 and 11'), but to no avail.
>
> I 've posted what I believe is the relevant code, maybe I didn't set the vertex data right in the geometry. The code here currently renders nothing.
>
>
> Code:
>
> Gluint vertloc = 0;
> Gluint colloc = 1;
>
> //
> OSG: geode * pyramidgeode = new OSG: geode ();
> Root-> addchild (pyramidgeode );
>
> // Geometry
> OSG: geometry * pyramidgeometry = new OSG: geometry ();
> Pyramidgeode-> adddrawable (pyramidgeometry );
>
> // Vertices
> OSG: vec3array * pyramidvertices = new OSG: vec3array;
>
> For (INT I = 0; I <model-> verticesnum; I ++ ){
> Float x = model-> positions [I * 3];
> Float y = model-> positions [I * 3 + 1];
> Float z = model-> positions [I * 3 + 2];
> Pyramidvertices-> push_back (OSG: vec3 (x, y, z ));
> }
>
>
> // Pyramidgeometry-> setvertexarray (pyramidvertices );
>
> Program-> addbindattriblocation ("a_vertex", vertloc );
> Pyramidgeometry-> setvertexattribarray (vertloc, pyramidvertices );
> Pyramidgeometry-> setvertexattribbinding (vertloc, OSG: geometry: bind_per_vertex );
> }
> // Colours
> OSG: vec4array * Colors = new OSG: vec4array;
>
> For (INT I = 0; I <model-> verticesnum; I ++ ){
> Float r = model-> Cols [I * 4];
> Float G = model-> Cols [I * 4 + 1];
> Float B = model-> Cols [I * 4 + 2];
> Float a = model-> Cols [I * 4 + 3];
> Colors-> push_back (OSG: vec4 (R, G, B, ));
> }
>
> Program-> addbindattriblocation ("a_col", colloc );
> Pyramidgeometry-> setvertexattribarray (colloc, colors );
> Pyramidgeometry-> setvertexattribbinding (colloc, OSG: geometry: bind_per_vertex );
> }
>
> // Indices
> OSG: drawelementsuint * pyramidbase = new OSG: drawelementsuint (OSG: primitiveset: triangles, model-> indicesnum, model-> indices, 0 );
> Pyramidgeometry-> addprimitiveset (pyramidbase );
>
>
>
>
> And the shaders
>
> Code:
>
> // Vertex shader
>
>
> Attribute vec3 a_vertex;
> Attribute vec4 a_col;
>
>
> Varying vec4 Col;
>
> Void main (){
> Col = a_col;
>
> // Gl_position = gl_modelviewprojectionmatrix * gl_vertex
> Gl_position = gl_modelviewprojectionmatrix * vec4 (a_vertex, 1.0 );
>
> }
>
> // Fragment shader
>
> Varying vec4 Col;
>
> Void main (){
> Gl_fragcolor = Col;
> }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.