From a27ce2390c22f195737fdf51a9f1fef2657ac320 Mon Sep 17 00:00:00 2001 From: Wilrik de Loose Date: Fri, 9 May 2008 12:20:24 +0000 Subject: newest menu demo + resolved conflicts --- menu_demo/Debug/BuildLog.htm | Bin 7160 -> 7240 bytes menu_demo/Debug/main.obj | Bin 13483 -> 19891 bytes menu_demo/Debug/menu.obj | Bin 23964 -> 25862 bytes menu_demo/Debug/menu_demo.exe | Bin 528384 -> 536576 bytes menu_demo/Debug/menu_demo.ilk | Bin 1293400 -> 1406936 bytes menu_demo/Debug/menu_demo.pdb | Bin 2108416 -> 2173952 bytes menu_demo/Debug/mt.dep | 2 +- menu_demo/Debug/vc80.idb | Bin 125952 -> 125952 bytes menu_demo/Debug/vc80.pdb | Bin 61440 -> 61440 bytes menu_demo/bitmap.c | 16 +++ menu_demo/bitmap.h | 1 + menu_demo/button.c | 202 ++++++++++++------------------ menu_demo/button.h | 10 +- menu_demo/font.c | 43 ++++--- menu_demo/font.h | 8 +- menu_demo/img/cursor.bmp | Bin 0 -> 65592 bytes menu_demo/img/images/photoshop/cursor.psd | Bin 0 -> 70019 bytes menu_demo/img/images/photoshop/title.psd | Bin 559888 -> 0 bytes menu_demo/main.c | 68 +++++++--- menu_demo/menu.c | 136 ++++++++++++-------- menu_demo/menu_demo.ncb | Bin 7891968 -> 8031232 bytes menu_demo/menu_demo.suo | Bin 29184 -> 31744 bytes menu_demo/menu_demo.vcproj | 2 +- 23 files changed, 264 insertions(+), 224 deletions(-) create mode 100644 menu_demo/img/cursor.bmp create mode 100644 menu_demo/img/images/photoshop/cursor.psd delete mode 100644 menu_demo/img/images/photoshop/title.psd diff --git a/menu_demo/Debug/BuildLog.htm b/menu_demo/Debug/BuildLog.htm index 9eeca4e..5224a06 100644 Binary files a/menu_demo/Debug/BuildLog.htm and b/menu_demo/Debug/BuildLog.htm differ diff --git a/menu_demo/Debug/main.obj b/menu_demo/Debug/main.obj index 0cb41a3..410bc0b 100644 Binary files a/menu_demo/Debug/main.obj and b/menu_demo/Debug/main.obj differ diff --git a/menu_demo/Debug/menu.obj b/menu_demo/Debug/menu.obj index 1c1b550..4ca8d2b 100644 Binary files a/menu_demo/Debug/menu.obj and b/menu_demo/Debug/menu.obj differ diff --git a/menu_demo/Debug/menu_demo.exe b/menu_demo/Debug/menu_demo.exe index 1a48381..0946df9 100644 Binary files a/menu_demo/Debug/menu_demo.exe and b/menu_demo/Debug/menu_demo.exe differ diff --git a/menu_demo/Debug/menu_demo.ilk b/menu_demo/Debug/menu_demo.ilk index 2aec88d..899d8d5 100644 Binary files a/menu_demo/Debug/menu_demo.ilk and b/menu_demo/Debug/menu_demo.ilk differ diff --git a/menu_demo/Debug/menu_demo.pdb b/menu_demo/Debug/menu_demo.pdb index da823dc..c44c423 100644 Binary files a/menu_demo/Debug/menu_demo.pdb and b/menu_demo/Debug/menu_demo.pdb differ diff --git a/menu_demo/Debug/mt.dep b/menu_demo/Debug/mt.dep index 9304fd2..4621ea4 100644 --- a/menu_demo/Debug/mt.dep +++ b/menu_demo/Debug/mt.dep @@ -1 +1 @@ -Manifest resource last updated at 1:37:15,66 on 26-04-2008 +Manifest resource last updated at 11:42:26,65 on 06-05-2008 diff --git a/menu_demo/Debug/vc80.idb b/menu_demo/Debug/vc80.idb index 43601f7..2dd1657 100644 Binary files a/menu_demo/Debug/vc80.idb and b/menu_demo/Debug/vc80.idb differ diff --git a/menu_demo/Debug/vc80.pdb b/menu_demo/Debug/vc80.pdb index 857ffa5..3810ecc 100644 Binary files a/menu_demo/Debug/vc80.pdb and b/menu_demo/Debug/vc80.pdb differ diff --git a/menu_demo/bitmap.c b/menu_demo/bitmap.c index 243952a..2d69bc9 100644 --- a/menu_demo/bitmap.c +++ b/menu_demo/bitmap.c @@ -3,6 +3,7 @@ #include #define GL_BGR 0x80E0 #define GL_BGRA 0x80E1 + #define GL_CLAMP_TO_EDGE 0x812F #endif #include @@ -69,6 +70,8 @@ struct BitmapStruct BitmapLoad(char *filename) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); l_sImage.m_iImageId = texture; l_sImage.m_iWidth = width; @@ -87,6 +90,19 @@ struct BitmapStruct BitmapLoad(char *filename) } +void BitmapRender(int f_iXPos, int f_iYPos, int f_iWidth, int f_iHeight, int f_iImageId) +{ + glBindTexture(GL_TEXTURE_2D, f_iImageId); + + glBegin(GL_TRIANGLE_STRIP); + glTexCoord2i(0, 1); glVertex2i(f_iXPos, f_iYPos); + glTexCoord2i(1, 1); glVertex2i(f_iXPos + f_iWidth, f_iYPos); + glTexCoord2i(0, 0); glVertex2i(f_iXPos, f_iYPos + f_iHeight); + glTexCoord2i(1, 0); glVertex2i(f_iXPos + f_iWidth, f_iYPos + f_iHeight); + glEnd(); + +} // BitmapRender + void BitmapConvertWidth(struct BitmapStruct *f_sImage, double f_dHeight) { diff --git a/menu_demo/bitmap.h b/menu_demo/bitmap.h index f86526b..3aaf5d1 100644 --- a/menu_demo/bitmap.h +++ b/menu_demo/bitmap.h @@ -8,6 +8,7 @@ struct BitmapStruct { }; struct BitmapStruct BitmapLoad(char *filename); +void BitmapRender(int f_iXPos, int f_iYPos, int f_iWidth, int f_iHeight, int f_iImageId); void BitmapConvertWidth(struct BitmapStruct *f_sImage, double f_dHeight); #endif diff --git a/menu_demo/button.c b/menu_demo/button.c index 82fe504..d452fd0 100644 --- a/menu_demo/button.c +++ b/menu_demo/button.c @@ -1,10 +1,10 @@ #ifdef G_OS_WIN32 #define WIN32_LEAN_AND_MEAN 1 - #include -#else - #define FALSE 0 - #define TRUE !FALSE - #define max(a, b) (((a) > (b)) ? (a) : (b)) + #include +#else + #define FALSE 0 + #define TRUE !FALSE + #define max(a, b) (((a) > (b)) ? (a) : (b)) #endif @@ -19,17 +19,16 @@ #include "font.h" - -struct ButtonStruct ButtonCreate(int f_dXPos, int f_dYPos, int f_dWidth, int f_dHeight, char *f_pcTitle, int f_iType, int f_iGroup, int f_iId) +struct ButtonStruct ButtonCreate(int f_iXPos, int f_iYPos, int f_iWidth, int f_iHeight, char *f_pcTitle, int f_iType, int f_iGroup, int f_iId) { struct ButtonStruct l_sButton; // copy parameters - l_sButton.m_dXPos = f_dXPos; - l_sButton.m_dYPos = f_dYPos; + l_sButton.m_iXPos = f_iXPos; + l_sButton.m_iYPos = f_iYPos; l_sButton.m_iType = f_iType; - l_sButton.m_dHeight = f_dHeight; - l_sButton.m_dWidth = f_dWidth; + l_sButton.m_iHeight = f_iHeight; + l_sButton.m_iWidth = f_iWidth; l_sButton.m_iGroup = f_iGroup; l_sButton.m_iId = f_iId; @@ -48,17 +47,17 @@ struct ButtonStruct ButtonCreate(int f_dXPos, int f_dYPos, int f_dWidth, int f_d l_sButton.m_psImgHover[1] = BitmapLoad("img/button_click_center_hover.bmp"); l_sButton.m_psImgHover[2] = BitmapLoad("img/button_click_right_hover.bmp"); - BitmapConvertWidth(&l_sButton.m_psImgNormal[0], f_dHeight); - BitmapConvertWidth(&l_sButton.m_psImgNormal[1], f_dHeight); - BitmapConvertWidth(&l_sButton.m_psImgNormal[2], f_dHeight); + BitmapConvertWidth(&l_sButton.m_psImgNormal[0], f_iHeight); + BitmapConvertWidth(&l_sButton.m_psImgNormal[1], f_iHeight); + BitmapConvertWidth(&l_sButton.m_psImgNormal[2], f_iHeight); - BitmapConvertWidth(&l_sButton.m_psImgHover[0], f_dHeight); - BitmapConvertWidth(&l_sButton.m_psImgHover[1], f_dHeight); - BitmapConvertWidth(&l_sButton.m_psImgHover[2], f_dHeight); + BitmapConvertWidth(&l_sButton.m_psImgHover[0], f_iHeight); + BitmapConvertWidth(&l_sButton.m_psImgHover[1], f_iHeight); + BitmapConvertWidth(&l_sButton.m_psImgHover[2], f_iHeight); // calculate (center)width of image - l_sButton.m_dCenterWidth = max(f_dWidth - l_sButton.m_psImgNormal[0].m_iWidth - l_sButton.m_psImgNormal[2].m_iWidth, 0); - l_sButton.m_dWidth = l_sButton.m_dCenterWidth + l_sButton.m_psImgNormal[0].m_iWidth + l_sButton.m_psImgNormal[2].m_iWidth; + l_sButton.m_iCenterWidth = max(f_iWidth - l_sButton.m_psImgNormal[0].m_iWidth - l_sButton.m_psImgNormal[2].m_iWidth, 0); + l_sButton.m_iWidth = l_sButton.m_iCenterWidth + l_sButton.m_psImgNormal[0].m_iWidth + l_sButton.m_psImgNormal[2].m_iWidth; break; case BUTTON_RADIO: @@ -66,13 +65,13 @@ struct ButtonStruct ButtonCreate(int f_dXPos, int f_dYPos, int f_dWidth, int f_d l_sButton.m_psImgHover[0] = BitmapLoad("img/button_radio_hover.bmp"); l_sButton.m_psImgPressed[0] = BitmapLoad("img/button_radio_pressed.bmp"); - BitmapConvertWidth(&l_sButton.m_psImgNormal[0], f_dHeight); - BitmapConvertWidth(&l_sButton.m_psImgHover[0], f_dHeight); - BitmapConvertWidth(&l_sButton.m_psImgPressed[0], f_dHeight); + BitmapConvertWidth(&l_sButton.m_psImgNormal[0], f_iHeight); + BitmapConvertWidth(&l_sButton.m_psImgHover[0], f_iHeight); + BitmapConvertWidth(&l_sButton.m_psImgPressed[0], f_iHeight); - l_sButton.m_dCenterWidth = 0; - l_sButton.m_dHeight = f_dHeight; - l_sButton.m_dWidth = f_dWidth; + l_sButton.m_iCenterWidth = 0; + l_sButton.m_iHeight = f_iHeight; + l_sButton.m_iWidth = f_iWidth; break; default: @@ -87,38 +86,36 @@ struct ButtonStruct ButtonCreate(int f_dXPos, int f_dYPos, int f_dWidth, int f_d } // ButtonCreate - void ButtonClickRender(struct ButtonStruct *f_sButton) { char l_pcTitle[BUTTON_MAX_TITLE]; struct BitmapStruct *l_sImgButton; - int l_iImgWidth, l_iImageIdLeft, l_iImageIdCenter, l_iImageIdRight; - int l_iLen, l_iXOffset, l_iYOffset; - double l_dXOffset, l_dYOffset; + int l_iImageIdLeft, l_iImageIdCenter, l_iImageIdRight; + int l_iLen, l_iXOffset, l_iYOffset, l_iWidth; struct ColorStruct l_sColor = {0, 0, 0}; // copy button attributes - double l_dCnWdt = f_sButton->m_dCenterWidth; - double l_dHeight = f_sButton->m_dHeight; - double l_dXPos = f_sButton->m_dXPos; - double l_dYPos = f_sButton->m_dYPos; + int l_iCnWdt = f_sButton->m_iCenterWidth; + int l_iHeight = f_sButton->m_iHeight; + int l_iXPos = f_sButton->m_iXPos; + int l_iYPos = f_sButton->m_iYPos; - l_iLen = (int)strlen(f_sButton->m_pcTitle); - l_iXOffset = (int)(0.5 * f_sButton->m_dWidth - 0.5 * l_iLen * FONT_SPACING); - l_iYOffset = (int)(0.5 * f_sButton->m_dHeight - 0.5 * FONT_HEIGHT); - - if (f_sButton->m_bPressed) { + if (f_sButton->m_bPressed) + { glColor3d(0.8, 0.9, 1); } - else { + else + { glColor3d(1, 1, 1); } // get the right image struct - if (f_sButton->m_bHover) { + if (f_sButton->m_bHover) + { l_sImgButton = f_sButton->m_psImgHover; } - else { + else + { l_sImgButton = f_sButton->m_psImgNormal; } @@ -131,76 +128,55 @@ void ButtonClickRender(struct ButtonStruct *f_sButton) memcpy(&l_pcTitle, f_sButton->m_pcTitle, strlen(f_sButton->m_pcTitle)); // render left side of button - glBindTexture(GL_TEXTURE_2D, l_iImageIdLeft); - - l_iImgWidth = l_sImgButton[0].m_iWidth; - l_dXOffset = l_dXPos; - l_dYOffset = l_dYPos; - - glBegin(GL_TRIANGLE_STRIP); - glTexCoord2d(0, 1); glVertex3d(l_dXOffset + 1, l_dYOffset, 0); - glTexCoord2d(1, 1); glVertex3d(l_dXOffset + l_iImgWidth, l_dYOffset, 0); - glTexCoord2d(0, 0); glVertex3d(l_dXOffset + 1, l_dYOffset + l_dHeight, 0); - glTexCoord2d(1, 0); glVertex3d(l_dXOffset + l_iImgWidth, l_dYOffset + l_dHeight, 0); - glEnd(); - - l_dXOffset = l_dXPos + l_iImgWidth + l_dCnWdt; + l_iWidth = l_sImgButton[0].m_iWidth; + BitmapRender(l_iXPos, + l_iYPos, + l_iWidth + 1, + l_iHeight, + l_iImageIdLeft); // render right side of button - glBindTexture(GL_TEXTURE_2D, l_iImageIdRight); - - l_iImgWidth = l_sImgButton[2].m_iWidth; - - glBegin(GL_TRIANGLE_STRIP); - glTexCoord2d(0, 1); glVertex3d(l_dXOffset - 1, l_dYOffset, 0); - glTexCoord2d(1, 1); glVertex3d(l_dXOffset + l_iImgWidth, l_dYOffset, 0); - glTexCoord2d(0, 0); glVertex3d(l_dXOffset - 1, l_dYOffset + l_dHeight, 0); - glTexCoord2d(1, 0); glVertex3d(l_dXOffset + l_iImgWidth, l_dYOffset + l_dHeight, 0); - glEnd(); - - l_dXOffset = l_dXOffset - l_dCnWdt; + l_iWidth = l_sImgButton[2].m_iWidth; + BitmapRender(l_iXPos + l_iCnWdt + l_iWidth - 1, + l_iYPos, + l_iWidth, + l_iHeight, + l_iImageIdRight); // render center of button - if (l_dCnWdt > 0) + if (l_iCnWdt > 0) { - glBindTexture(GL_TEXTURE_2D, l_iImageIdCenter); - - glBegin(GL_TRIANGLE_STRIP); - glTexCoord2d(0, 1); glVertex3d(l_dXOffset - 1, l_dYOffset, 0); - glTexCoord2d(1, 1); glVertex3d(l_dXOffset + l_dCnWdt, l_dYOffset, 0); - glTexCoord2d(0, 0); glVertex3d(l_dXOffset - 1, l_dYOffset + l_dHeight, 0); - glTexCoord2d(1, 0); glVertex3d(l_dXOffset + l_dCnWdt, l_dYOffset + l_dHeight, 0); - glEnd(); + BitmapRender(l_iXPos + l_iWidth - 1, + l_iYPos, + l_iCnWdt + 1, + l_iHeight, + l_iImageIdCenter); } - if (f_sButton->m_bPressed) - { - glColor3d(1, 1, 1); - } + l_iLen = (int)strlen(f_sButton->m_pcTitle); + l_iXOffset = (int)(0.5 * f_sButton->m_iWidth - 0.5 * l_iLen * FONT_SPACING); + l_iYOffset = (int)(0.5 * f_sButton->m_iHeight - 0.5 * FONT_HEIGHT); - glPrint(f_sButton->m_dXPos + l_iXOffset, - f_sButton->m_dYPos + l_iYOffset, + glPrint(f_sButton->m_iXPos + l_iXOffset, + f_sButton->m_iYPos + l_iYOffset, f_sButton->m_pcTitle, l_sColor); } // ButtonClickRender - void ButtonRadioRender(struct ButtonStruct *f_sButton) { struct BitmapStruct *l_sImgButton; - int l_iXOffset, l_iYOffset, l_iImageId; + int l_iXOffset, l_iYOffset, l_iImageRadioId, l_iImageEnabledId; // copy button attributes - double l_dWidth = f_sButton->m_dWidth; - double l_dHeight = f_sButton->m_dHeight; - double l_dXPos = f_sButton->m_dXPos; - double l_dYPos = f_sButton->m_dYPos; + int l_iWidth = f_sButton->m_iWidth; + int l_iHeight = f_sButton->m_iHeight; + int l_iXPos = f_sButton->m_iXPos; + int l_iYPos = f_sButton->m_iYPos; struct ColorStruct l_sColor = {0.2, 0.4, 0.8}; - glColor3d(1, 1, 1); - // get the right image struct if (f_sButton->m_bHover) { @@ -211,45 +187,31 @@ void ButtonRadioRender(struct ButtonStruct *f_sButton) l_sImgButton = f_sButton->m_psImgNormal; } - // copy buttom images - l_iImageId = l_sImgButton[0].m_iImageId; + l_iImageRadioId = l_sImgButton[0].m_iImageId; + l_iImageEnabledId = f_sButton->m_psImgPressed[0].m_iImageId; - // render left side of button - glBindTexture(GL_TEXTURE_2D, l_iImageId); + glColor3d(1, 1, 1); - glBegin(GL_TRIANGLE_STRIP); - glTexCoord2d(0, 1); glVertex3d(l_dXPos, l_dYPos, 0); - glTexCoord2d(1, 1); glVertex3d(l_dXPos + l_dWidth, l_dYPos, 0); - glTexCoord2d(0, 0); glVertex3d(l_dXPos, l_dYPos + l_dHeight, 0); - glTexCoord2d(1, 0); glVertex3d(l_dXPos + l_dWidth, l_dYPos + l_dHeight, 0); - glEnd(); + // render the radio button + BitmapRender(l_iXPos, l_iYPos, l_iWidth, l_iHeight, l_iImageRadioId); + // render the enable-dot if button is pressed if (f_sButton->m_bPressed) { - l_iImageId = f_sButton->m_psImgPressed[0].m_iImageId; - glBindTexture(GL_TEXTURE_2D, l_iImageId); - - glBegin(GL_TRIANGLE_STRIP); - glTexCoord2d(0, 1); glVertex3d(l_dXPos, l_dYPos, 0); - glTexCoord2d(1, 1); glVertex3d(l_dXPos + l_dWidth, l_dYPos, 0); - glTexCoord2d(0, 0); glVertex3d(l_dXPos, l_dYPos + l_dHeight, 0); - glTexCoord2d(1, 0); glVertex3d(l_dXPos + l_dWidth, l_dYPos + l_dHeight, 0); - glEnd(); + BitmapRender(l_iXPos, l_iYPos, l_iWidth, l_iHeight, l_iImageEnabledId); } - l_iXOffset = (int)f_sButton->m_dWidth; - l_iYOffset = (int)(0.5 * f_sButton->m_dHeight - 0.5 * FONT_HEIGHT); + l_iXOffset = (int)f_sButton->m_iWidth; + l_iYOffset = (int)(0.5 * f_sButton->m_iHeight - 0.5 * FONT_HEIGHT); - glPrint(f_sButton->m_dXPos + l_iXOffset, - f_sButton->m_dYPos + l_iYOffset, + glPrint(f_sButton->m_iXPos + l_iXOffset, + f_sButton->m_iYPos + l_iYOffset, f_sButton->m_pcTitle, l_sColor); } // ButtonRadioRender - - void ButtonRender(struct ButtonStruct *f_sButton) { int l_iType = f_sButton->m_iType; @@ -271,7 +233,6 @@ void ButtonRender(struct ButtonStruct *f_sButton) } // ButtonRender - void ButtonEnter(struct ButtonStruct *f_sButton) { f_sButton->m_bHover = TRUE; @@ -279,7 +240,6 @@ void ButtonEnter(struct ButtonStruct *f_sButton) } // ButtonHover - void ButtonExit(struct ButtonStruct *f_sButton) { f_sButton->m_bHover = FALSE; @@ -287,7 +247,6 @@ void ButtonExit(struct ButtonStruct *f_sButton) } // ButtonHover - void ButtonClickPress(struct ButtonStruct *f_sButton) { if (!f_sButton->m_bPressed) { @@ -297,7 +256,6 @@ void ButtonClickPress(struct ButtonStruct *f_sButton) } // ButtonClickPress - void ButtonRadioPress(struct ButtonStruct *f_sButton) { int i = 0; @@ -310,7 +268,6 @@ void ButtonRadioPress(struct ButtonStruct *f_sButton) } // ButtonClickPress - void ButtonPress(struct ButtonStruct *f_sButton) { int l_iType = f_sButton->m_iType; @@ -332,7 +289,6 @@ void ButtonPress(struct ButtonStruct *f_sButton) } // ButtonPress - void ButtonClickRelease(struct ButtonStruct *f_sButton) { ButtonDisable(f_sButton); @@ -340,7 +296,6 @@ void ButtonClickRelease(struct ButtonStruct *f_sButton) } // ButtonClickRelease - void ButtonRelease(struct ButtonStruct *f_sButton) { int l_iType = f_sButton->m_iType; @@ -359,7 +314,6 @@ void ButtonRelease(struct ButtonStruct *f_sButton) } // ButtonRelease - void ButtonEnable(struct ButtonStruct *f_sButton) { f_sButton->m_bPressed = TRUE; @@ -371,4 +325,4 @@ void ButtonDisable(struct ButtonStruct *f_sButton) { f_sButton->m_bPressed = FALSE; -} // ButtonDisable +} // ButtonDisable diff --git a/menu_demo/button.h b/menu_demo/button.h index c3521bb..d8f1fe5 100644 --- a/menu_demo/button.h +++ b/menu_demo/button.h @@ -8,11 +8,11 @@ #define BUTTON_CLICK_HEIGHT 49 struct ButtonStruct { - int m_dXPos; // x positie - int m_dYPos; // y positie - int m_dCenterWidth; // breedte van middenstuk - int m_dWidth; // totale breedte - int m_dHeight; // totale hoogte + int m_iXPos; // x positie + int m_iYPos; // y positie + int m_iCenterWidth; // breedte van middenstuk + int m_iWidth; // totale breedte + int m_iHeight; // totale hoogte int m_bPressed; // pressed or not int m_bHover; // mouse hovering or not int m_iType; // button type diff --git a/menu_demo/font.c b/menu_demo/font.c index e3773a5..0332174 100644 --- a/menu_demo/font.c +++ b/menu_demo/font.c @@ -1,12 +1,12 @@ #ifdef G_OS_WIN32 #define WIN32_LEAN_AND_MEAN 1 - #include -#else - #define FALSE 0 + #include +#else + #define FALSE 0 #define TRUE !FALSE #endif -#include +#include #include #include "font.h" @@ -17,38 +17,39 @@ struct BitmapStruct g_sFont; int g_iWinWidth; int g_iWinHeight; -GLuint base; +GLuint g_iBase; + void FontInit(int f_iWinWidth, int f_iWinHeight) { float cx; float cy; + int l_iImageId; int i = 0; + float x = (float)(1.0f/FONT_XCHAR); + g_iWinWidth = f_iWinWidth; g_iWinHeight = f_iWinHeight; g_sFont = BitmapLoad("img/continuum_textured_alpha.bmp"); + l_iImageId = g_sFont.m_iImageId; - base = glGenLists(256); - glBindTexture(GL_TEXTURE_2D, g_sFont.m_iImageId); + g_iBase = glGenLists(FONT_COUNT); + glBindTexture(GL_TEXTURE_2D, l_iImageId); - for (i = 0; i < 256; i++) + for (i = 0; i < FONT_COUNT; i++) { cx = (float)(i % 16) / 16.0f; cy = (float)(i / 16) / 16.0f; - glNewList(base + i, GL_COMPILE); + glNewList(g_iBase + i, GL_COMPILE); glBegin(GL_TRIANGLE_STRIP); - glTexCoord2f(cx, 1 - cy); - glVertex2i(0, 0); - glTexCoord2f(cx + 0.0625f, 1 - cy); - glVertex2i(FONT_WIDTH, 0); - glTexCoord2f(cx, 1 - cy - 0.0625f); - glVertex2i(0, FONT_HEIGHT); - glTexCoord2f(cx + 0.0625f, 1 - cy - 0.0625f); - glVertex2i(FONT_WIDTH, FONT_HEIGHT); + glTexCoord2f(cx, 1 - cy); glVertex2i(0, 0); + glTexCoord2f(cx + x, 1 - cy); glVertex2i(FONT_WIDTH, 0); + glTexCoord2f(cx, 1 - cy - x); glVertex2i(0, FONT_HEIGHT); + glTexCoord2f(cx + x, 1 - cy - x); glVertex2i(FONT_WIDTH, FONT_HEIGHT); glEnd(); glTranslated(FONT_SPACING, 0, 0); @@ -57,12 +58,14 @@ void FontInit(int f_iWinWidth, int f_iWinHeight) } // BuildFont + void FontDelete(void) { - glDeleteLists(base, 256); + glDeleteLists(g_iBase, FONT_COUNT); } // FontDelete + void glPrint(GLint x, GLint y, char *string, struct ColorStruct f_sColor) { glColor3d(f_sColor.m_dRed, f_sColor.m_dGreen, f_sColor.m_dBlue); @@ -77,11 +80,11 @@ void glPrint(GLint x, GLint y, char *string, struct ColorStruct f_sColor) glPushMatrix(); glLoadIdentity(); glTranslated(x, y, 0); - glListBase(base - 32); + glListBase(g_iBase - 32); glCallLists((GLsizei)strlen(string), GL_UNSIGNED_BYTE, string); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); -} // glPrint +} // glPrint diff --git a/menu_demo/font.h b/menu_demo/font.h index a7fa2a1..4e61850 100644 --- a/menu_demo/font.h +++ b/menu_demo/font.h @@ -1,9 +1,11 @@ #ifndef _CFONT_H #define _CFONT_H -#define FONT_WIDTH 32 -#define FONT_HEIGHT 32 -#define FONT_SPACING 20 +#define FONT_WIDTH 32 // width of a character (in the bitmap source!) +#define FONT_HEIGHT 32 // height of a character (in the bitmap source!) +#define FONT_SPACING 20 // spacing between characters when printing +#define FONT_XCHAR 16 // number of characters aligned on the x-axis in the bitmap source +#define FONT_COUNT 256 // number of characters in the bitmap source struct ColorStruct { double m_dRed; diff --git a/menu_demo/img/cursor.bmp b/menu_demo/img/cursor.bmp new file mode 100644 index 0000000..2af07e4 Binary files /dev/null and b/menu_demo/img/cursor.bmp differ diff --git a/menu_demo/img/images/photoshop/cursor.psd b/menu_demo/img/images/photoshop/cursor.psd new file mode 100644 index 0000000..2151d01 Binary files /dev/null and b/menu_demo/img/images/photoshop/cursor.psd differ diff --git a/menu_demo/img/images/photoshop/title.psd b/menu_demo/img/images/photoshop/title.psd deleted file mode 100644 index f9404d3..0000000 Binary files a/menu_demo/img/images/photoshop/title.psd and /dev/null differ diff --git a/menu_demo/main.c b/menu_demo/main.c index 68180ef..2cea607 100644 --- a/menu_demo/main.c +++ b/menu_demo/main.c @@ -4,10 +4,9 @@ #endif #include -#include - #include #include +#include #include "menu.h" @@ -15,34 +14,64 @@ #define SCREEN_HEIGHT 480 - void init_gl(void) { } // init_gl +void render_blox(void) +{ + static double l_dAngle = 0.0; + + glPushMatrix(); + glTranslated(0, 0, -20); + glTranslated(sin(l_dAngle * (float)3.1415 / 180.0f) * 5, + sin(l_dAngle * (float)3.1415 / 180.0f) * 5, + -5 + sin(l_dAngle * (float)3.1415 / 180.0f) * 5); + glRotated(l_dAngle, 0.5, 0.5, 1); + + // draw big cube + glutSolidCube(4); + + glPushMatrix(); + // draw smaller cube + glTranslated(0, sin(l_dAngle * (float)3.1415 / 180.0f) * 5, 0); + glutSolidCube(2); + glPopMatrix(); + + glPopMatrix(); + + l_dAngle += 0.1; + +} // render_blox + void render_scene(void) { + float l_pfMaterial[] = {1.0f, 0.4f, 0.0f, 0.0f}; + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glClearColor(1, 1, 1, 1); - - //// render teapot - //glMatrixMode(GL_PROJECTION); - //glPushMatrix(); - // glLoadIdentity(); - // gluPerspective(45, 1.0, 1.0, 200.0); - // glMatrixMode(GL_MODELVIEW); - // glTranslated(0, 0, -5); - // glColor3d(1, 0, 0); - // glutSolidTeapot(1); - // glTranslated(0, 0, 5); - // glMatrixMode(GL_PROJECTION); - //glPopMatrix(); + glClearColor(1, 0.4, 0.2, 1); + glDisable(GL_TEXTURE_2D); - MenuRender(); + // enable default lighting + glEnable(GL_DEPTH_TEST); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, l_pfMaterial); + + // render 3d shit + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(45, 1.0, 1.0, 100.0); + glMatrixMode(GL_MODELVIEW); + render_blox(); + + glDisable(GL_LIGHTING); + + MenuRender(); glutSwapBuffers(); } // render_scene @@ -102,8 +131,7 @@ int main(int argc, char **argv) init_gl(); MenuInit(SCREEN_WIDTH, SCREEN_HEIGHT); - glutEstablishOverlay(); - printf("Overlay %d\n", glutLayerGet(GLUT_OVERLAY_POSSIBLE)); + ShowCursor(FALSE); glutMainLoop(); diff --git a/menu_demo/menu.c b/menu_demo/menu.c index a36a916..9276850 100644 --- a/menu_demo/menu.c +++ b/menu_demo/menu.c @@ -6,7 +6,7 @@ #define TRUE !FALSE #endif -#include +#include #include #include #include @@ -18,6 +18,7 @@ #define MENU_MAX_BUTTONS 16 enum MenuState { + MENU_OFF, MENU_MAIN, MENU_START, MENU_OPTIONS @@ -29,14 +30,20 @@ struct MenuStruct { struct ButtonStruct m_sButtons[MENU_MAX_BUTTONS]; }; +struct MenuStruct g_sMenuOff; // definition of the menu when it's disabled (empty menu) struct MenuStruct g_sMenuMain; // definition of the main menu struct MenuStruct g_sMenuStart; // definition of the start menu struct MenuStruct g_sMenuOptions; // definition of the options menu struct MenuStruct *g_pCurMenu; // current menu +struct BitmapStruct g_sCursorImage; // bitmap struct of the cursor + int g_iWinWidth; int g_iWinHeight; +int g_iXPos; // last cursor pos +int g_iYPos; + void MenuEnableGroup(int f_iGroup) { @@ -65,7 +72,9 @@ void MenuEnableGroup(int f_iGroup) void MenuAddButton(int f_dXPos, int f_dYPos, int f_dWidth, int f_dHeight, char *f_pcTitle, int f_iType, int f_iGroup) { - int i = g_pCurMenu->m_iButtonCount;; + int i = g_pCurMenu->m_iButtonCount; + + if (i > MENU_MAX_BUTTONS - 1) return; // create the button with the right parameters g_pCurMenu->m_sButtons[i] = ButtonCreate(f_dXPos, f_dYPos, f_dWidth, f_dHeight, f_pcTitle, f_iType, f_iGroup, i); @@ -74,7 +83,6 @@ void MenuAddButton(int f_dXPos, int f_dYPos, int f_dWidth, int f_dHeight, char * } // MenuAddButton - void MenuClear(void) { g_pCurMenu->m_iButtonCount = 0; @@ -83,7 +91,6 @@ void MenuClear(void) } // MenuClear - void MenuBuild (void) { int l_iMenuId = g_pCurMenu->m_iMenuId; @@ -91,7 +98,15 @@ void MenuBuild (void) switch (l_iMenuId) { default: + case MENU_OFF: + // no buttons + break; + case MENU_MAIN: + MenuAddButton(200, 150, 256, 128, "START", BUTTON_CLICK, BUTTON_NO_GROUP); + break; + + case MENU_START: MenuAddButton(50, 50, 250, 64, "Button 1", BUTTON_CLICK, BUTTON_NO_GROUP); MenuAddButton(50, 150, 250, 64, "Button 2", BUTTON_CLICK, BUTTON_NO_GROUP); MenuAddButton(350, 50, 64, 64, "Radio 1", BUTTON_RADIO, BUTTON_GROUP1); @@ -105,44 +120,34 @@ void MenuBuild (void) MenuEnableGroup(BUTTON_GROUP2); break; - case MENU_START: + case MENU_OPTIONS: MenuAddButton(50, 150, 250, 64, "Start", BUTTON_CLICK, BUTTON_NO_GROUP); MenuAddButton(50, 250, 250, 64, "Back", BUTTON_CLICK, BUTTON_NO_GROUP); MenuAddButton(350, 150, 64, 64, "Try first!", BUTTON_RADIO, BUTTON_GROUP1); MenuAddButton(350, 250, 64, 64, "10 games", BUTTON_RADIO, BUTTON_GROUP1); MenuEnableGroup(BUTTON_GROUP1); break; - - case MENU_OPTIONS: - MenuAddButton(50, 50, 64, 64, "Headtracking", BUTTON_RADIO, BUTTON_GROUP1); - MenuAddButton(50, 150, 64, 64, "Stereo vision", BUTTON_RADIO, BUTTON_GROUP1); - MenuEnableGroup(BUTTON_GROUP1); - break; } } // MenuBuild - -void MenuRebuild(void) -{ - MenuClear(); - MenuBuild(); - -} // MenuRebuild - - - void MenuNext(void) { int l_iMenuId = g_pCurMenu->m_iMenuId; - l_iMenuId = (l_iMenuId + 1) % 3; - g_pCurMenu->m_iMenuId = l_iMenuId; - MenuRebuild(); + l_iMenuId = (l_iMenuId + 1) % 4; -} // MenuNext + switch (l_iMenuId) + { + default: + case MENU_OFF: g_pCurMenu = &g_sMenuOff; break; + case MENU_MAIN: g_pCurMenu = &g_sMenuMain; break; + case MENU_START: g_pCurMenu = &g_sMenuStart; break; + case MENU_OPTIONS: g_pCurMenu = &g_sMenuOptions; break; + } +} // MenuNext void MenuInit(int f_iWinWidth, int f_iWinHeight) @@ -150,27 +155,38 @@ void MenuInit(int f_iWinWidth, int f_iWinHeight) // init menu props g_iWinWidth = f_iWinWidth; g_iWinHeight = f_iWinHeight; + g_iXPos = -100; + g_iYPos = -100; - // set pointer to the current menu - g_pCurMenu = &g_sMenuStart; + // init main off + g_sMenuOff.m_iMenuId = MENU_OFF; + g_pCurMenu = &g_sMenuOff; + MenuBuild(); // init main menu g_sMenuMain.m_iMenuId = MENU_MAIN; + g_pCurMenu = &g_sMenuMain; + MenuBuild(); // init start menu g_sMenuStart.m_iMenuId = MENU_START; + g_pCurMenu = &g_sMenuStart; + MenuBuild(); // init options menu g_sMenuOptions.m_iMenuId = MENU_OPTIONS; + g_pCurMenu = &g_sMenuOptions; + MenuBuild(); // init font FontInit(f_iWinWidth, f_iWinHeight); - // build the current menu (main) - MenuBuild(); + g_pCurMenu = &g_sMenuOff; -} // MenuInit + // load cursor image + g_sCursorImage = BitmapLoad("img/cursor.bmp"); +} // MenuInit void MenuRender(void) @@ -182,8 +198,6 @@ void MenuRender(void) glDisable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); - glColor4d(1, 1, 1, 1); - glMatrixMode(GL_PROJECTION); glPushMatrix(); @@ -192,14 +206,37 @@ void MenuRender(void) glMatrixMode(GL_MODELVIEW); glEnable(GL_BLEND); + + if (g_pCurMenu->m_iMenuId != MENU_OFF) + { + glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR); + + glColor3d(0.6, 0.6, 0.7); + glBegin(GL_TRIANGLE_STRIP); + glVertex2i(0, 0); + glVertex2i(g_iWinWidth, 0); + glVertex2i(0, g_iWinHeight); + glVertex2i(g_iWinWidth, g_iWinHeight); + glEnd(); + } + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // render the buttons of the current menu for (i; i < g_pCurMenu->m_iButtonCount; i++) { + glColor4d(1, 1, 1, 1); ButtonRender(&g_pCurMenu->m_sButtons[i]); } + // render cursor + glColor3d(1, 1, 1); + BitmapRender(g_iXPos, + g_iYPos, + 64, //g_sCursorImage.m_iWidth, + 64, //g_sCursorImage.m_iHeight, + g_sCursorImage.m_iImageId); + glDisable(GL_BLEND); //restore the previous projection matrix @@ -210,31 +247,28 @@ void MenuRender(void) } // MenuRender - int MenuCollision(struct ButtonStruct *f_sButton, int f_iXPos, int f_iYPos) { - int l_iCollision; + int l_bCollision; int l_iButtonX, l_iButtonY; int l_iButtonWidth, l_iButtonHeight; - l_iButtonX = f_sButton->m_dXPos; - l_iButtonY = f_sButton->m_dYPos; - l_iButtonWidth = f_sButton->m_dWidth; - l_iButtonHeight = f_sButton->m_dHeight; - - l_iCollision = f_iXPos >= l_iButtonX; - l_iCollision &= f_iYPos >= l_iButtonY; - l_iCollision &= f_iXPos <= l_iButtonX + l_iButtonWidth; - l_iCollision &= f_iYPos <= l_iButtonY + l_iButtonHeight; + l_iButtonX = f_sButton->m_iXPos; + l_iButtonY = f_sButton->m_iYPos; + l_iButtonWidth = f_sButton->m_iWidth; + l_iButtonHeight = f_sButton->m_iHeight; + l_bCollision = f_iXPos >= l_iButtonX; + l_bCollision &= f_iYPos >= l_iButtonY; + l_bCollision &= f_iXPos <= l_iButtonX + l_iButtonWidth; + l_bCollision &= f_iYPos <= l_iButtonY + l_iButtonHeight; - if (l_iCollision) return TRUE; + if (l_bCollision) return TRUE; return FALSE; } // MenuCollision - void MenuMouseClick(int f_iGlutButton, int f_iGlutState, int f_iXPos, int f_iYPos) { int i = 0; @@ -259,10 +293,10 @@ void MenuMouseClick(int f_iGlutButton, int f_iGlutState, int f_iXPos, int f_iYPo for (i; i >= 0; i--) { l_sButton = g_pCurMenu->m_sButtons[i]; - l_iXPos = l_sButton.m_dXPos; - l_iYPos = l_sButton.m_dYPos; - l_iWidth = l_sButton.m_dWidth; - l_iHeight = l_sButton.m_dHeight; + l_iXPos = l_sButton.m_iXPos; + l_iYPos = l_sButton.m_iYPos; + l_iWidth = l_sButton.m_iWidth; + l_iHeight = l_sButton.m_iHeight; l_iType = l_sButton.m_iType; l_iId = l_sButton.m_iId; l_iGroup = l_sButton.m_iGroup; @@ -303,6 +337,9 @@ void MenuMouseMove(int f_iXPos, int f_iYPos) int i = 0; struct ButtonStruct l_sButton; + g_iXPos = f_iXPos; + g_iYPos = f_iYPos; + // check if any button needs attention from the mouse for (i; i < g_pCurMenu->m_iButtonCount; i++) { @@ -320,4 +357,3 @@ void MenuMouseMove(int f_iXPos, int f_iYPos) } // MenuMouseMove - diff --git a/menu_demo/menu_demo.ncb b/menu_demo/menu_demo.ncb index b7b2f16..47e06d3 100644 Binary files a/menu_demo/menu_demo.ncb and b/menu_demo/menu_demo.ncb differ diff --git a/menu_demo/menu_demo.suo b/menu_demo/menu_demo.suo index e420b9e..0882a45 100644 Binary files a/menu_demo/menu_demo.suo and b/menu_demo/menu_demo.suo differ diff --git a/menu_demo/menu_demo.vcproj b/menu_demo/menu_demo.vcproj index 79af145..07198ca 100644 --- a/menu_demo/menu_demo.vcproj +++ b/menu_demo/menu_demo.vcproj @@ -42,7 +42,7 @@ Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories=""D:\My Documents\TUe\2iv55\menu_demo\include"" - PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;G_OS_WIN32" + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;G_OS_WIN32;_CRT_SECURE_NO_DEPRECATE" MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="1" -- cgit v0.12