This topic is 5463 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

How can this be done... for example if i had a material file that had:
window {
texture window.tga
blend GL_SRC_ALPHA GL_ONE
}


How can i read that from the file and then use it to blend in GL... I noticed that quake 3 engine does this in it's .shader files... how is it done?! thanks!

Share on other sites
There's no magic involved with this kind of thing. On the most basic level, you just need to read this data in memory, scan it, and recognize 'oh, this is a texture name' and 'oh, this is the blending mode i need to use'.

If you want to be quick and dirty about it, you could just do a strstr for "texture" and then you know the texture filename is what comes next. Then you can do a strstr for "blend" and you know that the blending constants come next. You can then do a strcmp against "GL_SRC_ALPHA" (etc..) to find which modes are being used, and set some variables to the proper constants.

The process of picking data out like this is generally called "parsing". Look into strtok() for help with basic parsing. If you want to get advanced you can use things like lexx and yacc, which are pretty heavy duty parsing tools.

Share on other sites
I already have written the code to read the file correctly, my only problem is converting GL_SRC_ALPHA from an std::string to the enum value.... any ideas?

Share on other sites
Gluint EnumVal;
if(MyString == "GL_SRC_ALPHA") EnumVal = GL_SRC_ALPHA;
if(MyString == "GL_ONE") EnumVal = GL_ONE;

Share on other sites
if (thestring == "GL_SRC_ALPHA")
theenum = GL_SRC_ALPHA;
else if (thestring == "GL_SRC_COLOR")
theenum = GL_SRC_COLOR;

etc.

easy.

you'd could also put it in a table or something, and just loop through it until you get a string match... or just a std::map kinda thing, i guess...

it's really a trivial problem with loads of solutions, just use whichever method will make mistakes the most obvious when you're looking at the code... with such a small number of values, i wouldn't bother trying to do anything fancy...

Share on other sites
Hehe!! Direct3D has .fx files [lol]

Share on other sites
Quote:
 Original post by Pipo DeClownHehe!! Direct3D has .fx files [lol]

I guess that makes you better than the rest of us, doesn't it?

Share on other sites
Quote:
 Original post by Pipo DeClownHehe!! Direct3D has .fx files [lol]

Hehe!! I'm not limited to Windows [lol]

lol, sorry, had to say it :p

Thanks for the tips guys.. I knew that it was possible to do the way you guys posted, but I thought there was another way where i wouldnt have to if statement every possibillity... but thanks!

Share on other sites
Quote:
 Original post by Pipo DeClownHehe!! Direct3D has .fx files [lol]

Hehe!! I'm not limited to Windows [lol]

lol, sorry, had to say it :p

Thanks for the tips guys.. I knew that it was possible to do the way you guys posted, but I thought there was another way where i wouldnt have to if statement every possibillity... but thanks!

Share on other sites
heres what i do

static opengl_string_with_define opengl_1_1_defines[] =
{

// Version
"GL_VERSION_1_1", 1

// AccumOp
,"GL_ACCUM", 0x0100
,"GL_RETURN", 0x0102
,"GL_MULT", 0x0103

// AlphaFunction
,"GL_NEVER", 0x0200
,"GL_LESS", 0x0201
,"GL_EQUAL", 0x0202
,"GL_LEQUAL", 0x0203
,"GL_GREATER", 0x0204
,"GL_NOTEQUAL", 0x0205
,"GL_GEQUAL", 0x0206
,"GL_ALWAYS", 0x0207

,"GL_CURRENT_BIT", 0x00000001
,"GL_POINT_BIT", 0x00000002
,"GL_LINE_BIT",

etc

from memory it took about 1/2 hour to make the whole list.
gl.h + gl_ext.h

• Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 22
• 17
• 46