Jump to content
  • Advertisement
Sign in to follow this  
iwoplaza

OpenGL OpenGL, in game GUI

This topic is 2266 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

OpenGL, in game GUI


[color=#000000][font=arial, sans-serif]

[background=rgb(245, 245, 245)]I've tried[/background][/font][font=arial, sans-serif]

[background=rgb(245, 245, 245)] [/background][/font][font=arial, sans-serif]

[background=rgb(245, 245, 245)]to create a[/background][/font][font=arial, sans-serif]

[background=rgb(245, 245, 245)] [/background][/font][font=arial, sans-serif]

[background=rgb(245, 245, 245)]GUI[/background][/font][font=arial, sans-serif]

[background=rgb(245, 245, 245)] [/background][/font][font=arial, sans-serif]

[background=rgb(245, 245, 245)]in the[/background][/font][font=arial, sans-serif]

[background=rgb(245, 245, 245)] [/background][/font][font=arial, sans-serif]

[background=rgb(245, 245, 245)]background of[/background][/font][font=arial, sans-serif]

[background=rgb(245, 245, 245)] [/background][/font][font=arial, sans-serif]

[background=rgb(245, 245, 245)]the game,[/background][/font][font=arial, sans-serif]

[background=rgb(245, 245, 245)] [/background][/font][font=arial, sans-serif]

[background=rgb(245, 245, 245)]where will be showed[/background][/font][font=arial, sans-serif]

[background=rgb(245, 245, 245)] [/background][/font][font=arial, sans-serif]

[background=rgb(245, 245, 245)]the amount of money[/background][/font][font=arial, sans-serif]

[background=rgb(245, 245, 245)], the amount[/background][/font][font=arial, sans-serif]

[background=rgb(245, 245, 245)] [/background][/font][font=arial, sans-serif]

[background=rgb(245, 245, 245)]of life[/background][/font][font=arial, sans-serif]

[background=rgb(245, 245, 245)] [/background][/font][font=arial, sans-serif]

[background=rgb(245, 245, 245)]etc. and I don't know how to make it sad.png. I want it to look like that:[/background][/font]


asdozx.png



Can you help me?


P.S. I'm sorry for my bad English.

Edited by iwoplaza

Share this post


Link to post
Share on other sites
Advertisement


void __fastcall draw4x3()
{
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex2f(0,0);
glTexCoord2f(1,0);
glVertex2f(FCOpenGL->Width,0);
glTexCoord2f(1,1);
glVertex2f(FCOpenGL->Width,FCOpenGL->Height);
glTexCoord2f(0,1);
glVertex2f(0,FCOpenGL->Height);
glEnd();
}

if (draw_2d_menu == true) {
glPushAttrib(GL_DEPTH_TEST); // Save the current Depth test settings (Used for blending )
glDisable(GL_DEPTH_TEST); // Turn off depth testing (otherwise we get no FPS)

glMatrixMode(GL_PROJECTION); // Switch to the projection matrix
glPushMatrix(); // Save current projection matrix
glLoadIdentity();
// GetWindowRect(GetDesktopWindow(), drawRect); // Get current window size
glOrtho(0, FCOpenGL->Width, 0, FCOpenGL->Height, -1, 1); // Change the projection matrix using an orthgraphic projection
glMatrixMode(GL_MODELVIEW); // Return to the modelview matrix
glPushMatrix(); // Save the current modelview matrix
glLoadIdentity();
glColor3f(1.0, 1.0, 1.0); // Text color
glEnable(GL_TEXTURE_2D); // Restore the old base list
// glEnable(GL_BLEND);
//
// glBlendFunc(GL_ONE,GL_ONE);
glBindTexture(GL_TEXTURE_2D,MENUE);
draw4x3();
//glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
glMatrixMode(GL_PROJECTION); //Switch to projection matrix
glPopMatrix(); // Restore the old projection matrix
glMatrixMode(GL_MODELVIEW); // Return to modelview matrix
glPopMatrix(); // Restore old modelview matrix
glPopAttrib(); // Restore depth testing

}



for displ;aying text is more trickier

you must build font list context


void BuildFont2(unsigned int & Ufont, int size)
{
HFONT font;
Ufont = glGenLists(256); // Generate enough display lists to hold
font = CreateFont(size, // height of font
0, // average character width
0, // angle of escapement
0, // base-line orientation angle
FW_BOLD, // font weight
0, // italic
0, // underline
0, // strikeout
DEFAULT_CHARSET, // character set
OUT_TT_PRECIS, // output precision
CLIP_DEFAULT_PRECIS, // clipping precision
ANTIALIASED_QUALITY, // output quality
FF_DONTCARE || DEFAULT_PITCH, // pitch and family
"Courier New"); // font
SelectObject((*dc), font); // Sets the new font as the current font in the device context
wglUseFontBitmaps((*dc), 0, 256, Ufont); // Creates a set display lists containing the bitmap fonts

}



how to initialize this
===================================================================
------------------ thease are global - global for opengl window class called here FCOpenGL
unsigned int titleb;
HDC dc;
----------------


HDC*ki=new HDC;
(*ki)=FCOpenGL->dc;
Initialize_OPENGL_ATTACH(ki,FCOpenGL->Width,FCOpenGL->Height);

====================================================================
void __fastcall Initialize_OPENGL_ATTACH(HDC *adc,int w, int h)
{
dc = adc; //this dc is not from FCOpenGL because its in different file this is: HDC * dc; so it's a pointer the procedure buildfont is in the same file as this proc
BuildFont2(titleb,38);
WINDOW_HEIGHT = h;
WINDOW_WIDTH = w;
}






and ad last writing text



void glWriteTEXT(int X,int Y, AnsiString text)
{
glPushAttrib(GL_DEPTH_TEST); // Save the current Depth test settings (Used for blending )
glDisable(GL_DEPTH_TEST); // Turn off depth testing (otherwise we get no FPS)

glMatrixMode(GL_PROJECTION); // Switch to the projection matrix
glPushMatrix(); // Save current projection matrix
glLoadIdentity();
// GetWindowRect(GetDesktopWindow(), drawRect); // Get current window size
glOrtho(0, WINDOW_WIDTH, 0, WINDOW_HEIGHT, -1, 1); // Change the projection matrix using an orthgraphic projection
glMatrixMode(GL_MODELVIEW); // Return to the modelview matrix
glPushMatrix(); // Save the current modelview matrix
glLoadIdentity();
// glColor3f(1.0, 1.0, 1.0); // Text color
glRasterPos2i(X, Y); // Position the Text
glPushAttrib(GL_LIST_BIT); // Save's the current base list
glListBase(base); // Set the base list to our character list
glCallLists(text.Length(), GL_UNSIGNED_BYTE, text.c_str()); // Display the text
glPopAttrib(); // Restore the old base list
glMatrixMode(GL_PROJECTION); //Switch to projection matrix
glPopMatrix(); // Restore the old projection matrix
glMatrixMode(GL_MODELVIEW); // Return to modelview matrix
glPopMatrix(); // Restore old modelview matrix

glPopAttrib(); // Restore depth testing

}



you can also download source from here
https://sites.google.com/site/imoomohomozumo/documents/OPENGL_ATTACH.cpp?attredirects=0&d=1
https://sites.google.com/site/imoomohomozumo/documents/OPENGL_ATTACH.h?attredirects=0&d=1 Edited by ___

Share this post


Link to post
Share on other sites
I have problem with that code unsure.png . Im working in Dev-C++ and I have errors.
This is my code of GUI:


////
////GUI Code
////
unsigned int titleb;
HDC dc;
HDC*ki=new HDC;
(ki)=FCOpenGL->dc;
Initialize_OPENGL_ATTACH(ki,FCOpenGL->Width,FCOpenGL->Height);
void __fastcall Initialize_OPENGL_ATTACH(HDC *adc,int w, int h)
{
BuildFont2(titleb,38);
WINDOW_HEIGHT = h;
WINDOW_WIDTH = w;
}
void __fastcall draw4x3()
{
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex2f(0,0);
glTexCoord2f(1,0);
glVertex2f(FCOpenGL->Width,0);
glTexCoord2f(1,1);
glVertex2f(FCOpenGL->Width,FCOpenGL->Height);
glTexCoord2f(0,1);
glVertex2f(0,FCOpenGL->Height);
glEnd();
}
if (draw_2d_menu == true) {
glPushAttrib(GL_DEPTH_TEST); // Save the current Depth test settings (Used for blending )
glDisable(GL_DEPTH_TEST); // Turn off depth testing (otherwise we get no FPS) glMatrixMode(GL_PROJECTION); // Switch to the projection matrix
glPushMatrix(); // Save current projection matrix
glLoadIdentity();
// GetWindowRect(GetDesktopWindow(), drawRect); // Get current window size
glOrtho(0, FCOpenGL->Width, 0, FCOpenGL->Height, -1, 1); // Change the projection matrix using an orthgraphic projection
glMatrixMode(GL_MODELVIEW); // Return to the modelview matrix
glPushMatrix(); // Save the current modelview matrix
glLoadIdentity();
glColor3f(1.0, 1.0, 1.0); // Text color
glEnable(GL_TEXTURE_2D); // Restore the old base list
// glEnable(GL_BLEND);
//
// glBlendFunc(GL_ONE,GL_ONE);
glBindTexture(GL_TEXTURE_2D,MENUE);
draw4x3();
//glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
glMatrixMode(GL_PROJECTION); //Switch to projection matrix
glPopMatrix(); // Restore the old projection matrix
glMatrixMode(GL_MODELVIEW); // Return to modelview matrix
glPopMatrix(); // Restore old modelview matrix
glPopAttrib(); // Restore depth testing
}
void BuildFont2(unsigned int & Ufont, int size)
{
HFONT font;
Ufont = glGenLists(256); // Generate enough display lists to hold
font = CreateFont(size, // height of font
0, // average character width
0, // angle of escapement
0, // base-line orientation angle
FW_BOLD, // font weight
0, // italic
0, // underline
0, // strikeout
DEFAULT_CHARSET, // character set
OUT_TT_PRECIS, // output precision
CLIP_DEFAULT_PRECIS, // clipping precision
ANTIALIASED_QUALITY, // output quality
FF_DONTCARE || DEFAULT_PITCH, // pitch and family
"Courier New"); // font
SelectObject((*dc), font); // Sets the new font as the current font in the device context
wglUseFontBitmaps((*dc), 0, 256, Ufont); // Creates a set display lists containing the bitmap fonts}
////GUI Code


What I'm doing wrong.

Share this post


Link to post
Share on other sites
Errors:
-cannot convert `HDC__' to `HDC__*' for argument `1' to `void* SelectObject(HDC__*, void*)'
-cannot convert `HDC__' to `HDC__*' for argument `1' to `BOOL wglUseFontBitmapsA(HDC__*, DWORD, DWORD, DWORD)'
-expected constructor, destructor, or type conversion before '=' token
-expected `,' or `;' before '=' token
-expected constructor, destructor, or type conversion before '(' token
-expected `,' or `;' before '(' token
-In function `void Initialize_OPENGL_ATTACH(HDC__**, int, int)':
-`BuildFont2' undeclared (first use this function)
-(Each undeclared identifier is reported only once for each function it appears in.)
-`WINDOW_HEIGHT' undeclared (first use this function)
-`WINDOW_WIDTH' undeclared (first use this function)
-In function `void draw4x3()':
-`FCOpenGL' undeclared (first use this function)
-At global scope:
-expected unqualified-id before "if"
-expected `,' or `;' before "if"
- In function `void BuildFont2(unsigned int&, int)':
-`void BuildFont2(unsigned int&, int)' used prior to declaration
- cannot convert `HDC__' to `HDC__*' for argument `1' to `void* SelectObject(HDC__*, void*)'
- cannot convert `HDC__' to `HDC__*' for argument `1' to `BOOL wglUseFontBitmapsA(HDC__*, DWORD, DWORD, DWORD)'
- [Build Error] [main.o] Error 1

Share this post


Link to post
Share on other sites

void __fastcall Initialize_OPENGL_ATTACH(HDC *adc,int w, int h)
{
dc = adc; //this dc is not from FCOpenGL because its in different file this is: HDC * dc; so it's a pointer the procedure buildfont is in the same file as this proc
BuildFont2(titleb,38);
WINDOW_HEIGHT = h;
WINDOW_WIDTH = w;
}


In Line "dc = adc;" is error. Why its wrong?

Share this post


Link to post
Share on other sites
first of all selectobject and wglbitamp whate ever is used in wingdi.h


second thing is that FCOpenGL->dc is the opengl device context



PIXELFORMATDESCRIPTOR pfd;
int pf;


dc = GetDC( FCOpenGL->Handle ); <--- SEEE ?
ZeroMemory( &pfd, sizeof( pfd));
pfd.nSize = sizeof( pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 32; pfd.cStencilBits = 8;
pfd.iLayerType = PFD_MAIN_PLANE;

pf = ChoosePixelFormat(dc, &pfd);
SetPixelFormat(dc, pf, &pfd);
rc = wglCreateContext(dc);
wglMakeCurrent(dc,rc);



initialize openglattach sets its own dc (pointer) to point onto this FCOpenGL->dc (device context)


you use only one HDC dc;(the FCOpenGL device context - opengl window context)

and in opengl_attach.h there is almost similar var called HDC *dc; BUT THIS IS A POINTER


so the steps you must achieve:

CREATE OPENGL WINDOW (you create device and rendering contexts)
then you do opengl_attach_initialize();


HDC*ki=new HDC;
(*ki)=FCOpenGL->dc; the opengl device context
Initialize_OPENGL_ATTACH(ki,Width,Height); <-- set the pointer to point onto our opengl device context...



you misunderstood what you must put into those functions you cannot create a global variable HDC dc; (that is your opengkl device context)
sad.png




OK IN OTHER WORD I THINK YOU WANT TO PUT THIS ALL INTO ONE SINGLE FILE SO READ NOW:

create variables

HGLRC rc;// : ; // Rendering Context
HDC dc;// : ; // Device Context
etc.
HDC *dc_SSH;
unsigned int base; //our font list

CREATE OPENGL DEVICE AND RENDERING CONTEXT (opengl window)

the dc is HDC dc; (getwindowdc(COMPONENT->Handle);) every win32 control has its own handle (or not every but in most cases)

replace dc with dc_SSH in code below


void BuildFont(unsigned int & Ufont)
{
HFONT font;
Ufont = glGenLists(256); // Generate enough display lists to hold
font = CreateFont(22, // height of font
0, // average character width
0, // angle of escapement
0, // base-line orientation angle
FW_BOLD, // font weight
0, // italic
0, // underline
0, // strikeout
DEFAULT_CHARSET, // character set
OUT_TT_PRECIS, // output precision
CLIP_DEFAULT_PRECIS, // clipping precision
ANTIALIASED_QUALITY, // output quality
FF_DONTCARE || DEFAULT_PITCH, // pitch and family
"Courier New"); // font
SelectObject((*dc), font); // Sets the new font as the current font in the device context
wglUseFontBitmaps((*dc), 0, 256, Ufont); // Creates a set display lists containing the bitmap fonts

}


AFTER VREATING OPENGL WINDOW AND INITIALIZING OPENGL



HDC*ki=new HDC;

(*ki)=dc;

Initialize_OPENGL_ATTACH(ki,Width,Height);

where

void __fastcall Initialize_OPENGL_ATTACH(HDC *adc,int w, int h)
{
dc_SSH = adc;
BuildFont(base);


}


that should do the trick

or delete pointers and (*) surrounding opengl device context

it is only a typecast (*int) is equal to int Edited by ___

Share this post


Link to post
Share on other sites
You send me link to source code that does not work too well. I had to a little change it. Although it's still not working. Can you send me the completed source code?

Share this post


Link to post
Share on other sites
i gave you everything you need to get it working, tell my what problems you have now, you do something wrong

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!