Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In OpenGL with C#, I am setting ambient and diffuse material properties for a complied glList containing triangles in Windows Paint event.

Typically I use,

C#
void Control_Paint(object sender, PaintEventArgs e)
{
....
float[] CustomColor = { 0.5f, 0.0f, 0.5f, 0.8f };
if(UserInputColor == true)
 gl.Materialfv(gl.FRONT_AND_BACK, gl.AMBIENT_AND_DIFFUSE, CustomColor);
gl.CallList(listId);
....
....
}


In the first call UserInputColor value is true.
In the subsequent calls of the Paint event UserInputColor value could be false.

I see that the material properties are retaining the previously set values in subsequent paint events.

In my case, I want to retain only the gl.FRONT & gl.AMBIENT settings at the end of Paint event. Retaining these values would make me to optimize on unnecessary setting of properties in every Paint event.

I do not want gl.BACK & gl.DIFFUSEto be retained if the UserInputColor variable is false. So I want to clear them off at the end of the event.

Is there a way to restore specific material properties after the execution of a compiled glList through any OpenGL command?
Posted
Updated 15-Apr-14 20:50pm
v2
Comments
Sergey Alexandrovich Kryukov 16-Apr-14 1:41am    
Have those properties been damaged? :-)
—SA
Anand V_ 16-Apr-14 2:30am    
Thanks for your comment. In a way... Yes.
User input will cause a change in the Ambient color on next paint event. In such a case I do not need Diffuse properties to be retained.

I would reframe my Question's Code block so as to give a better picture.

1 solution

What's wrong in restoring original values immediately before leaving the method?
 
Share this answer
 
Comments
Anand V_ 16-Apr-14 23:23pm    
@CPallini, Restoring all the material properties makes me to define them in every paint event. I am looking for partial restore / reset. Please let me know if there is a way to do it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900