Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Unable to display a simple OpenGL shape in ViewPort 2.0 with Strict OpenGL

Unable to display a simple OpenGL shape in ViewPort 2.0 with Strict OpenGL

Anonymous
Not applicable
3,356 Views
10 Replies
Message 1 of 11

Unable to display a simple OpenGL shape in ViewPort 2.0 with Strict OpenGL

Anonymous
Not applicable

Hi,

I have an MPxLocator in which I want to do some simple OpenGL (VBO), like drawing a triangle.

However the Strict OpenGL (vs Legacy) requires additional steps, and I am unable to understand what these steps are:

Do I need, and how, to create a specific context ?

Is there a sample source code showing some OpenGL been drawn on ViewPort 2.0 with Strict OpenGL ?

What's the high-level process to display OpenGL Code ?

Thanks !

0 Likes
Accepted solutions (1)
3,357 Views
10 Replies
Replies (10)
Message 2 of 11

Anonymous
Not applicable

And to complement my question, if I want to use VAO and VBO, must I compile a shader absolutely or can I do it without shader ?

0 Likes
Message 3 of 11

Anonymous
Not applicable

Hi,

 

did you created already a MPxDrawOverride class? You need this class to draw in Viewport 2.0. MPxLocatorNode is just for legacy viewport rendering.

Inside the MPxDrawOverride you have to override some methods and inside the draw(...) method you can call OpenGL commands, if Maya use OpenGL API and not DirectX API.

 

Here is an example. However, this example use the addUIDrawables(...) method instead of the draw(). Inside the addUIDrawables you can add simple objects (like lines, box, ...) supported by Maya for all render API's. Additionally you must override the draw() method to make your OpenGL draws.

http://help.autodesk.com/view/MAYAUL/2016/ENU/?guid=__cpp_ref_simple_evaluation_draw_2simple_evaluat...

 

Maybe you need also to override the prepareForDraw() method to optimize your code.

0 Likes
Message 4 of 11

Anonymous
Not applicable
Accepted solution

Thanks Sven. I am already using DrawOverrides, and unfortunately AddUIDrawables is re-executed at each refresh and can't store data in the GPU as OpenGL would do.

However I found out my issue and parsing much more the internet. Seeming I HAD to use vertex glsl shaders (I thought they were optional).

I can now properly display OpenGL shapes.

0 Likes
Message 5 of 11

talk2rene
Contributor
Contributor

Hello,

 

You are saying "I HAD to use vertex glsl shaders". Can you elaborate perhaps on how you have achieved this? Do you still use a MPxDrawOverride approach or did you use a completely different MPx class perhaps?

 

I also wonder if your OpenGL shapes appear in the RENDER view (using Maya Hardware 2.0)?

 

Any pointers would be great.

 

Thanks, -rene

 

PS I got a custom MPxLocatorNode that draws some simple OpenGL shapes in the ViewPort 2.0 (using the MPxDrawOverride approach). However I would like to see the OpenGL shapes in the Renderview as well (using Maya Hardware 2.0), currently I do not see it being rendered in the Renderview, presumably because it needs a shader. Hence my interest in your solution.  

 

 

0 Likes
Message 6 of 11

Anonymous
Not applicable

In the overriden draw method, I am linking an openGl (glsl) program and this program receives the "order" to draw openGL.

 

Code extract:

 

{
glUseProgram(program); glUniformMatrix4fv(glGetUniformLocation(program, "projectionMatrix"), 1, GL_FALSE, projectionMat); glUniformMatrix4fv(glGetUniformLocation(program, "modelViewMatrix"), 1, GL_FALSE, modelViewMat); glUniformMatrix4fv(glGetUniformLocation(program, "translateMatrix"), 1, GL_FALSE, translateMat); glUniform3f(glGetUniformLocation(program, "cameraVector"), cameraVec[0],cameraVec[1],cameraVec[2]);

glUniform1i(glGetUniformLocation(program, "useNormal"), (GLuint)1);
glUniform1i(glGetUniformLocation(program, "isLine"), (GLuint)0);
glUniform3f(glGetUniformLocation(program, "DrawColor"), col1,col2,col3);
glBindVertexArray(0);

for (int v=0;v<data->nbVaoIDs;v++)
{
glBindVertexArray(vaoIDs); // Bind our Vertex Array Object
glDrawArrays(GL_TRIANGLES, 0, nbVertices);

}

glBindVertexArray(0);
}

 

 

It's indeed displayed properly in the Viewport 2.0, but obviously not when rendering. To see it while rendering, it depends on the renderer and your plugin will receive a given signal based on it (I personnally use VRay). What you can do is to "bake" your geometry before rendering, or, and I didn't try this, use MPxgeometryOverride's.

0 Likes
Message 7 of 11

talk2rene
Contributor
Contributor

Thank you for your reply and for the info.

 

I am currently writing a 'skeleton' plugin that uses the combo MPxLocatorNode and MPxGeometryOverride. My aim is to show a simple wire frame skeleton (i.e. a bunch of line primitives) in the VP2.0 and to get it rendered in Maya render by means of Maya Hardware 2.0. For now I am using an even simpler geometry, 1 line i.e. 2 vertices, just to get things working. 

 

I got the footPrint_geometryOverride sample from the devkit working in the VP2.0 (also simple primitives in wire frame mode) so I am confident that I will get my skeleton plugin working in VP2.0.

 

However, with footPrint_geometryOverride, I do not see anything rendered in the render view by using Maya Hardware 2.0. I put a global light in the scene for good measure. I played with the render override attributes in the attribute editor but to no avail. The same for Maya Hardware 2.0 settings (I have a Quadro NVidia card).

 

I am new to the shader world, my expertise is more in the Maya API vertex world. So you have to excuse me for not fully understanding of what is going on in terms of shaders and the Maya Hardware 2.0 render.

 

MPxGeometryOverride is using Maya stock shader & vertex/normals buffers and hence I thought that any renderer in Maya (Maya Hardware 2.0, VRay, Arnold) would recognize the stock shader and do something with the vertex/normals data such that it would show the line primitive in the rendered image (in either Maya's renderview or in the resulting image file). The Maya documentation alludes to that but perhaps there is more involved?

 

My question is... what else is needed, other than a stock shader and vertex/normals buffers, to get a primitive showing up in the rendered images? I somehow feel that I am missing an essential detail. Any pointers/thoughts would be appreciated!! Thank you! 

0 Likes
Message 8 of 11

talk2rene
Contributor
Contributor

Thanks for adding that code snippet! Very useful.

 

However for now I am interested in getting the MPxGeometryOverride to work in conjunction with a renderer (see my other comment I posted today). 

0 Likes
Message 9 of 11

talk2rene
Contributor
Contributor

I realize that I may be deviating from the topic of this thread... I have been able to draw primitives in the Maya Viewport 2.0 either with MPxDrawOverride (using OpenGL statements) or MPxGeometryOverride (by using the stock shader and setting a vertex & normals buffer).

 

In the latter case, as the primitive is drawn in the Maya Viewport 2.0 and irrespective of the drawing mode (wireFrame/Shaded), I clearly see the calls to

MPxGeometryOverride::updateDG()
MPxGeometryOverride::updateRenderItems()
MPxGeometryOverride::isIndexingDirty()
MPxGeometryOverride::populateGeometry()

 

 

However, in contrast to the Viewport 2.0, when I do a render using the Maya Hardware 2.0 renderer I do not see any of these 4 calls being made and hence that might be the reason perhaps why the renderer produces a black image? (Yes I put a global light in the scene). This kind of suggests that MPxGeometryOverride does not get a signal from the Maya Hardware 2.0 renderer in order to provide a shader and vertex & normals buffers.

 

EarthHobbit mentions in his previous post that VRay does send a signal to the Maya plugin in order to start a render.

 

So the challenge seems to be how to trigger the MPxGeometryOverride calls from the Maya Hardware 2.0 renderer. I will do more digging. In the mean while any more thoughts/pointers would be welcome!

 

Thanks! -rene 

 

 

0 Likes
Message 10 of 11

Anonymous
Not applicable
0 Likes
Message 11 of 11

talk2rene
Contributor
Contributor

Problem solved by making changes to the "Object Type Filter" panel of the "Maya Render 2.0" renderer. This panel is only visible when one opens the "render Options" panel.

 

Open Render->Render Settings panel

Choose "Maya Render 2.0" tab

Open "Render options" panel

Open "Object Type Filter" panel

Select "All" or just the objects you prefer

 

Now the custom locator shape shows up in the render view and in the corresponding image file. 

 

No need to invoke special callback calls to trigger the "Maya Render 2.0" renderer. The latter is invoked internally by Maya which in turn invoke the various MPxGeometryOverride calls.