Sign in to follow this  
Supremacy Song

OpenGL Autocomplete Tool in GLSL Editor

Recommended Posts

Hey guys, i'm a kind of begginer on OpenGL. I have created a TextBox in C++ with an Input Event Manager, what that's actually getting if some key of the kkeyboard was pressed and update the text on the textbox with these key pressed. I have too a text file with all the reserved words of GLSL sintaxys(gl_Position, uniform variable, vec3, ect....). Since here everything is okay, now the problems comes when i want to add the autocompletion tool (a string that get these input keys pressed and if some of them is actually same as some of the words of these text files, create a box with an scrollbar to shows this up and write it into the textbox is some of these words was selected clicking enter or with left mouse button, and then delete the memory size of these string to make a loop). As you can see in these longer parenthesys i have more or less the theory but, i don't have any idea how to start to developing it, cuz as far as i know there are no functions that actually makes that in the windows header(yeh im using Windows.h to create the textbox and the input manager, i thought i should had added these at the start). SO i would have to develop it by my own, which is hard for a newbie c++ programmer(i start learn it as same time ago as opengl). So if anybody here gives me an idea about how to start or how draw a box where you include all the words of these syntaxis glsl file, it would be awesome :D.

Share this post


Link to post
Share on other sites

If you are a newbie c++ programmer I would recommend switching to c# for this. It is far easier to do any type of form programming. I just had a go since I was curious and I got the basics going in about 10 minutes (a window with a text box in, when you start typing it opens up a little box at the end of your word with a list of suggestions. It only works for one word but that's easily solved (finding the last word in a text box is simple enough). It's just a form with a textbox and a listbox on it and then one event function for the textbox:

private void textBox1_TextChanged(object sender, EventArgs e)
        {
            string[] words = new string[5];
            words[0] = "gl_Position";
            words[1] = "uniform";
            words[2] = "varying";
            words[3] = "vec2";
            words[4] = "vec3";
 
            listBox1.Hide();
 
            TextBox tb = (TextBox)sender;
            string text = tb.Text;
            if (text.Length == 0)
                return;
 
            List<int> potential = new List<int>();
            for(int i = 0; i < 5; i++)
            {
                if (text.Length >= words[i].Length)
                    continue;
                if(!words[i].StartsWith(text))
                    continue;
                potential.Add(i);
            }
            if (potential.Count == 0)
                return;
            Point pos = tb.GetPositionFromCharIndex(text.Length-1);
            pos.X += tb.Location.X + 10;
            pos.Y += tb.Location.Y + 20;
 
            listBox1.Items.Clear();
            foreach(var item in potential)
            {
                listBox1.Items.Add(words[item]);
            }
            listBox1.Location = pos;
            listBox1.Show();
        }
I can't say that code is the best but it does show how little is needed to get going.
 
Choose the right tool for the job, c++ is great but not so great when you want a simple form type program. Java or c# beat it easily and are much friendlier to work with. I would recommend c# since you are into c++.

 

 

Share this post


Link to post
Share on other sites

I knew that C# with windows forms was easy to get this kid of job, but when i noticed that the Autocomplete class doesn't support multi-line TextBox's i come to try out with c++, after trying to create a custom listbox as an autocomplete class. But if you suggest me to forget about C++ then i would do that on C#. Thx :D, i would publish that editor as fast i can get it developed(that would have a little window at the left of the textbox that wikl show up your shader rendered in some different primitives polygons forms, something like ShaderToy but as local app).

Share this post


Link to post
Share on other sites

that would have a little window at the left of the textbox that wikl show up your shader rendered in some different primitives polygons forms, something like ShaderToy but as local app

 

Sounds like a cool idea.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this