Jump to content
  • Advertisement
Sign in to follow this  
colinisinhere

OpenGL Loading OpenGL enums from a file?

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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 this post


Link to post
Share on other sites
Quote:
Original post by Pipo DeClown
Hehe!! Direct3D has .fx files [lol]


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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Pipo DeClown
Hehe!! 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 this post


Link to post
Share on other sites
Quote:
Original post by Pipo DeClown
Hehe!! 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 this post


Link to post
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_LOAD", 0x0101
,"GL_RETURN", 0x0102
,"GL_MULT", 0x0103
,"GL_ADD", 0x0104

// 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

// AttribMask
,"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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!