GLenum = editbox text? (Win32/OGL question)

This is a discussion on GLenum = editbox text? (Win32/OGL question) within the Windows Programming forums, part of the Platform Specific Boards category; I have a dialog box in which i have 7 text boxs. they each are for 7 parameters in a ...

  1. #1
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070

    GLenum = editbox text? (Win32/OGL question)

    I have a dialog box in which i have 7 text boxs.
    they each are for 7 parameters in a function i have created for creating a light in openGL.
    the parameters are:
    name (GL_LIGHT0, GL_LIGHT1, etc)
    position x
    position y
    position z
    red
    green
    blue

    i can get every parameter to be taken from the editboxs except for the name.

    basicly my question is, how do i get a GLenum value to = edit box text?

    any help will be very much appreciated!

    -psychopath
    Memorial University of Newfoundland
    Computer Science

    Mac and OpenGL evangelist.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    You could use string comparison to get the relevant values (GLenum) for the corresponding string identifier from the edit control.

    Another possibility is to use a listbox - that way you could add the GLenum values as item data to the list items which you could retrieve when that particular value (or multiple values if you require multi-selection) is chosen. See LB_SETITEMDATA for more information if you're interested in trying that as an alternative.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    >>You could use string comparison to get the relevant values (GLenum) for the corresponding string identifier from the edit control.<<
    if you mean somthing like (for example):
    Code:
    GLenum name;
    char c_name;
    
    c_name = getthetextfromthetextboxetc();
    name = c_name;
    CreateNewLight(name, posX, posY etc etc);
    then i tried that and it diddn't work (light diddn't appear);

    a listbox probably won't work in this particular situation.

    If it helps, here is the code, tho it dosn't have anything done to get the 'name' value from the textbox (as nothing i tried worked ;P), and the name parameter in the CreateNewLight(); function is replaced with GL_LIGHT0, just so i could see if there was nothing wrong with the light code itself

    Code:
    BOOL CALLBACK LightInsertDlgProc(HWND hWnd, UINT Message, WPARAM wparam, LPARAM lparam)
    {
        switch(Message)
        {
            case WM_INITDIALOG:
    
            return TRUE;
            case WM_COMMAND:
                switch(LOWORD(wparam))
                {
    			case IDOK:
    				BOOL bSuccess1;
    				BOOL bSuccess2;
    				BOOL bSuccess3;
    				BOOL bSuccess4;
    				BOOL bSuccess5;
    				BOOL bSuccess6;
    				BOOL bSuccess7;
    				
    				GLenum name;
    				float posX;
    				float posY;
    				float posZ;
    				float red;
    				float green;
    				float blue;
    
    				posX = GetDlgItemInt(hWnd, IDPOSXBOX, &bSuccess1, FALSE);
    				posY = GetDlgItemInt(hWnd, IDPOSXBOX, &bSuccess2, FALSE);
    				posZ = GetDlgItemInt(hWnd, IDPOSXBOX, &bSuccess3, FALSE);
    				red = GetDlgItemInt(hWnd, IDREDBOX, &bSuccess4, FALSE);
    				green = GetDlgItemInt(hWnd, IDGREENBOX, &bSuccess5, FALSE);
    				blue = GetDlgItemInt(hWnd, IDBLUEBOX, &bSuccess6, FALSE);
    				
    
    				CreateNewLight(GL_LIGHT0, posX, posY, posZ, red, green, blue);
    				EndDialog(hWnd, IDCANCEL);
    				break;
    			
    			case IDCANCEL:
    				EndDialog(hWnd, IDCANCEL);
                    break;
                }
            break;
            default:
                return FALSE;
        }
        return TRUE;
    }
    -psychopath
    Memorial University of Newfoundland
    Computer Science

    Mac and OpenGL evangelist.

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    There is no built-in way to get a enum value from its name at run-time. We must build a lookup table that will let us match a string name to its value. This thread provides a method to create a lookup table. Once we have a lookup table we can search through it looking for the provided string. We could also use it to add the values to a list box.

    Code:
    #define BIND(x)   {x,#x}
    
    struct StringToGlEnum
    {
       GLenum      value;
       const char* name;
    }
    GlEnumNameLookupTable = 
    {
    	BIND(GL_LIGHT0),
    	BIND(GL_LIGHT1)
    
    	// More values here as needed.
    }
    
    
    int main(void)
    {
    	int i;
    	char test[] = "GL_LIGHT1"; // Assume this value came from a control
    
    	// Now we can lookup the value of GL_LIGHT1 in our lookup table
    
    	for (i = 0;i < sizeof(GlEnumNameLookupTable) / GlEnumNameLookupTable[0];i++)
    	{
    		if (strcmp(test, GlEnumNameLookupTable[i].name) == 0)
    		{
    			printf("The value of %s is %d\n", test, GlEnumNameLookupTable[i].value);
    			break;
    		}
    	}
    
    	getchar();
    	return 0;
    }

  5. #5
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    sorry for the late post...iv'e been away for a while.

    yea i'll try this...actually i have it half implemented, but like i said, iv'e been away for a while, so i havn't been able to work on this much.

    -psychopath
    Memorial University of Newfoundland
    Computer Science

    Mac and OpenGL evangelist.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Saving EditBox text
    By Queatrix in forum Windows Programming
    Replies: 5
    Last Post: 04-26-2005, 01:52 PM
  2. text simple question
    By Unregistered in forum Game Programming
    Replies: 2
    Last Post: 04-26-2002, 09:45 AM
  3. another text game question
    By Unregistered in forum Game Programming
    Replies: 4
    Last Post: 03-09-2002, 10:02 PM
  4. Text Game Question
    By Unregistered in forum Game Programming
    Replies: 4
    Last Post: 03-08-2002, 03:55 AM
  5. quick question about C Dos text menu pgm i was doing
    By Shadow in forum C Programming
    Replies: 2
    Last Post: 09-16-2001, 10:26 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21