[Basics] OpenGL material properties

Sorry for this naive question, but how can I get/calculate this OpenGL material values? (the number in brackets indicates how many arguments array should have):


I have done something similar rather recently. If you mean to export Blender Materials so that the OpenGL Materials look rather similar to the Blender render images, you can use the following Python script:

for m in obj.getData().materials:
    # Ambience #
    file.write(pack('f', m.amb * m.R))
    file.write(pack('f', m.amb * m.G))
    file.write(pack('f', m.amb * m.B))
    file.write(pack('f', m.alpha))
    # Diffuse #
    file.write(pack('f', m.R))
    file.write(pack('f', m.G))
    file.write(pack('f', m.B))
    file.write(pack('f', m.alpha))
    # Specular #
    file.write(pack('f', m.specCol[0] * m.spec * 2.0))
    file.write(pack('f', m.specCol[1] * m.spec * 2.0))
    file.write(pack('f', m.specCol[2] * m.spec * 2.0))
    file.write(pack('f', m.specTransp))
    # Emission #
    file.write(pack('f', m.emit * m.R))
    file.write(pack('f', m.emit * m.G))
    file.write(pack('f', m.emit * m.B))
    file.write(pack('f', m.alpha))
    # Shininess #
    file.write(pack('I', (m.hard/4)))
    # Alpha #
    file.write(pack('f', m.alpha))

That is for writing the Matial properties for all matarials to a binary file.

In C I used the following for the OpenGL Materials:

glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, MAT(ob,m)->Ambient);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MAT(ob,m)->Diffuse);
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, MAT(ob,m)->Emission);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, MAT(ob,m)->Specular);
glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, MAT(ob,m)->Shininess);

I hope this helps.

I looked at my C code and rememberd that I used a macro (MAT(ob,m), which is basically (ob->material + m).

I started to rewrite my exporter and OpenGL renderer to be structured better, but I sort of lost interest in the project a while back.