Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Mathimetric

Member Since 10 Mar 2013
Offline Last Active Jan 16 2014 12:21 PM

Posts I've Made

In Topic: How to get user writing input string in openGl?

09 January 2014 - 11:20 AM

@ Moudy I can try to find a source for this example (a HEllo World example)

but it will be un-related to the Hex editor -converter dipicted in the screen shot.

 

if thats ok? ; I will attach it to this messge when I have it together.

 

 

here is an alternate example of  GetString using OpenGL and windows library

-So in function the *strng is updated (represinting a Line) via the stream buffer gBuff [ ]

-when the return key check (rtrn) is  (>) greater then (Order) ; the function returns the string length of *strng -

and stops updating the *strng

 

the reason it looks this way is because it is meant to be inserted into a windows Loop or Application window Loop.

functions that are inside a window are a little different then the normal console apps' sometimes.

 

-class interface design-

class GLText
public:
    int BuffPos, sBuffPos,
    First, Count1, Count2;
    unsigned int base;
    unsigned int m_fontListBase;
    GLYPHMETRICSFLOAT gmf[256];   // holds orientation and placement
                                  // info for display lists

     GLText();
    ~GLText();

    bool Init(char *fontname, int fontsize, float depth);
    unsigned int CreateOutlineFont(char *fontname, int fontsize, float depth);
    void PositionFont(float xPos, float yPos, float zPos);
    void PrintFont(int order, const char *__format, ...);
    void CenterFont();
    void ReleaseFont(unsigned int base);
    int  ScanFont(int order, const char *__format, ...);
    void NewLine(float Mult = 1, float X = 0, float Y = 0, float Z = 0, char *Direction = "down");
    bool Shutdown();
    void Return0(void *var, char *type, int elms); //same as memset (...) for string
    int  GetString(int Order, char *strng);
    int rtrn;
    char *pBuff;
    char *sBuff;
    char *gBuff;
    char text[256];
int GLText::GetString(int Order, char *strng)
{
if(Order<=rtrn)
{
if (Order == rtrn )
{
 glPushAttrib(GL_LIST_BIT);
        glListBase(base);
        glCallLists(strlen(gBuff), GL_UNSIGNED_BYTE, gBuff);
 glPopAttrib();
        strng[BuffPos] = gBuff[BuffPos];
        strcpy(strng, gBuff);
return 0;
}
else
if(Order <= rtrn)
{
        glPushAttrib(GL_LIST_BIT);
        glListBase(base);
        glCallLists(strlen(strng), GL_UNSIGNED_BYTE, strng);
 glPopAttrib();
return strlen(strng);
}
return 0;
}
else
return strlen(strng);
}

I attached the class function def source code in src.cpp.txt

you will need to use your knowledge of C++ to piece them together for compilation/debugging/porting or use in another instance.

 

You can do 1 of 2 things with it

1. you could just include (src.cpp) it to the appended end of the class body Def

2. precompile it and link it with the H and the Main.cpp with the OBJ file

(this also includes letting microsofts visual studio LInk the resources with (h/cpp))

 

Summary:

this class will allow you, if you are using openGL (v1.0 or greater) 3d perspectives or ortho (ithink), a pixel pallete window application (WIN32); To draw 3d text on to the screen. Givin also the interface' to use input/output UI via keyboard or simulair (drivin) hardware.

--another requirement is that the window(x/s) APP must have a procedure for handling the window and its messeges--

 

your skill level needs to be intermediate to advanced to understand how to compile or port this into your own apps.

creating a window App is not an easy task for the beginner. You need to understand your own compiler and interfaces,

and some compiler's dont always have the nessesary DLL's included in its default libraies; so sometimes you need to know how to

find them and import them.


In Topic: Build UI in OpenGL for my 3D game world?

30 December 2013 - 11:25 AM

Just so you understand that

Mouse coord' system only uses 2 deminsions X,Y

the coord starts from the Top zero and the left zero (going top to  (<, greater) down, and left to  (<, greater) right)

You dont need to use Ortho graphic projection to use a 2d (or 3D) GUI.

 

the default OpenGL matrix is 4 x 4 units,

if you do that math and a little guessing or debugging, it is simple enough to

match your mouse Position checks with your Cursor and buttons.

 

when the screen position or size is changed

 

code:

//inside MainWindowProc  (these are your handles for your window and GUI)

//(windows messege SIZE)

//(windows messege MOVE)

 

// dispatch messages
 switch (uMsg)

{

//...

 

case WM_SIZE:
  height = HIWORD(lParam);  // retrieve width and height
  width = LOWORD(lParam);
// ~(update mouse coords' center "relative")~ //

 

case WM_MOVE:

//~(update new mouse postions relative to new RECT screen position)~//
// Mouse_.GetRectPos(windowRect); //

 

Example thumb PIC (JPEG)

Attached File  ex1.JPG   814.71KB   3 downloads


In Topic: How to get user writing input string in openGl?

27 December 2013 - 08:14 PM

quik simple example

inside  ~ MainWindowProc ~

(I have used this to print 3D text from user keyboard input)

 

 

Attached File  example.JPG   25.14KB   1 downloads

 

 
//                                                                  //
    case WM_CHAR:
    switch(wParam)
    {
    case VK_BACK:
    if(print.BuffPos)
    print.text[--print.BuffPos] = 0;
    if(print.sBuffPos)
    print.gBuff[--print.sBuffPos] = 0;
    break;
    case VK_RETURN:
    print.text[++print.BuffPos] = NULL;
    print.gBuff[++print.sBuffPos] = NULL;
    print.Return0(print.text,"char", 256);
    print.BuffPos = 0;
    print.Return0(print.gBuff, "char", 256);
    print.sBuffPos = 0;
    ++print.rtrn;
    break;
 case VK_NEXT:
 //MoonT.translation[1] -= 2;
 break;
 case VK_PRIOR:
 //MoonT.translation[1] += 2;
 break;
 break;
 break;
 
 case VK_LEFT:
        break;
 
 case VK_RIGHT:
      break;
 case VK_DOWN:     
 break;
 
 case VK_UP:      
 break;
    default:
    print.text[print.BuffPos] = (TCHAR) wParam;
    print.gBuff[print.sBuffPos] = (TCHAR) wParam;
    ++print.BuffPos;    ++print.sBuffPos;
    break;
    }
    break;
//                                                                    //
////////////////////////////////////////////////////////////////////////
 
Notice when a key is entered (printable character)
the switch is defaulted to update a string buffer.
--when enter key is depressed the handle Ends buffer with a NULL terminate char
|- then updates the data "rtrn" member to allow the program to know what line or how many times
the return key has been pressed. - this info is passed to the graphics functions for render()
 
-when the backspace key is pressed the string buffer's current Position is  zero'ed , and decrimented (pos) to re-enter the key that needs to be edited.
 
 
*in this case the buffer is used simulair to an I/O stream buffer in witch the buffer can be used to pass data to parameter's givin to
a function or class member function; such as GetString(int Rtn_order, char * format, ...)
 
Original standard streaming I/O buffers uses access of the Keyboard buffer and passes its data to a TEMP file buffer
{
(I.E.)
 
extern  FILE        _RTLENTRY _EXPDATA _streams[];
extern  unsigned    _RTLENTRY _EXPDATA _nfile;
 
stdin   (&_streams[0])
stdout  (&_streams[1])
stderr  (&_streams[2])
}
and C string Buffer's using BIOS (basic input/output instruction Sets')

In Topic: Build UI in OpenGL for my 3D game world?

27 December 2013 - 07:41 PM

*with mouse driver: you can draw your interface using photo shop,

*add animated buttons, similair to a web page design (hover, click ; textures),

then interact with your GUI using Test POS XY relative to screen pos (if not full screen) and by checking if your mouse button is

down or up. Then you have to support those handles for your buttons;

what will they do when clicked, or hovered over?.

 

example is coded using c/C++ (oop/structured)

//FILE MouseClass.h //
//windows mouse driver
//using windows library
//handles are usually updated via win main Loop, and passed data to windows handle
 
#include <windows.h>
#include <winuser.h>
#include <windef.h>
//simple example for winmouse class
//for using the windows mouse
//POINT  members { long x,y }
class WinMouse
{
private:
POINT CP;  //cursor position
public:
HWND windH;
RECT RectA;
long x, y;
long cx,cy;
int button1, button2;
WinMouse();
~WinMouse();
long CalcWindowX();
long CalcWindowY();
void ResetPos(long, long);
void GetRectPos(RECT );
void GetPos();
void SetPos(long x,long y);
void SetCenter();
void GetCenter();
void UpdateWindowCenter();
long GetX();
long GetY();
PosTest(int x, int y, int tx, int ty);
//note needed for relative mouse pos
//rect->left - GetX() , rect->top - GetY()
//GetWindowRect(HWND,RECT IN PTR)
//then Call
//this->GetRectPos(RECT );
};

////////////////////function definitions/////////////////////

WinMouse::WinMouse()
{
button1 = 0;
button2 = 0;
x=0;
y=0;
cx = 0;
cy = 0;
}
WinMouse::~WinMouse()
{
}
void WinMouse::UpdateWindowCenter()
{
this->GetPos();
 this->x = GetX() - this->cx;
 this->y = GetY() - this->cy;
}
WinMouse::PosTest(int x, int y, int tx, int ty)
{
 if(x < (GetX() -RectA.left ) && x + tx > (GetX() -RectA.left ))
 {
  if( y < (GetY() - RectA.top) && y + ty > (GetY() - RectA.top) )
  return 1;
  else
  return 0;
 }
 else
 return 0;
}
void WinMouse::GetCenter()
{
 x = (RectA.right + RectA.left)/2;
 y = (RectA.top + RectA.bottom)/2;
 
 cx = x;
 cy = y;
}
void WinMouse::SetCenter()
{
 x = RectA.left + RectA.right;
 y = RectA.top + RectA.bottom;  
 
 cx = x/2;
 cy = y/2;
 SetCursorPos(x/2,y/2);
}
 
void WinMouse::GetRectPos(RECT RectW)
{
 
 RectA.left = RectW.left;
 RectA.right = RectW.right;
 RectA.top = RectW.top;
 RectA.bottom = RectW.bottom;
}
long WinMouse::CalcWindowX()
{
 return this->RectA.right + this->RectA.left;
}
long WinMouse::CalcWindowY()
{
 return this->RectA.top + this->RectA.bottom;
}
 
void WinMouse::ResetPos(long Width, long Height)
{
 this->x = (long)(Width * (float).5);
 this->y = (long)(Height * (float).5);
SetCursorPos( this->x , this->y );
}
void WinMouse::SetPos(long x, long y)
{
SetCursorPos(x, y);
}
void WinMouse::GetPos()
{
GetCursorPos(&this->CP);
}
long WinMouse::GetX()
{
 return this->CP.x;
 
}
long WinMouse::GetY()
{
 return this->CP.y;
 
}
 
//EOF

In Topic: C++ String to a number

15 March 2013 - 12:27 PM

EDITED DUE TOO THE COMMENT BELOW FROM MODERATION:

ABOUT THE PROGRAM' MEMORY LEAK; (FIX)

 

did you try checking the string[Lvalue] characters by using...

 

<ctype.h>

 

int _RTLENTRY _EXPFUNC isalnum (int __c);
int _RTLENTRY _EXPFUNC isalpha (int __c);
int _RTLENTRY _EXPFUNC iscntrl (int __c);
int _RTLENTRY _EXPFUNC isdigit (int __c);
int _RTLENTRY _EXPFUNC isgraph (int __c);
int _RTLENTRY _EXPFUNC islower (int __c);
int _RTLENTRY _EXPFUNC isprint (int __c);
int _RTLENTRY _EXPFUNC ispunct (int __c);
int _RTLENTRY _EXPFUNC isspace (int __c);
int _RTLENTRY _EXPFUNC isupper (int __c);
int _RTLENTRY _EXPFUNC isxdigit(int __c);
int _RTLENTRY _EXPFUNC isascii (int __c);

 

you could use these to maybe determine if you have a number or not.

you could also try being more specific to handling the errors by using a pointer return value

 

such as

typedef <type> number_;

 

//(EDIT)/////////////////////////////////////////////////////////////////

// pointer rtn is givin a static address only 1 time so there is no memory leaks'

//

number_ * stringtonum(string_type  *)

{

static number_ * rtn;                               

if( rtn == NULL){ rtn = new number_[2]; }

 

//where rtn[0] == error handle , rtn[1] == converted num

//.........do conversion block ..............///

 

return rtn;  //return address to variable rtn

}

 

 

example impliment:

 

#define out<<        ....

#define error_       ....

 

if(   (*(stringtonum(data)+0)) ) out<<error_; //is there an error in rtn?

 else

assign = (*(stringtonum(data)+1));

 

 

 

///edited to ocommidate  the BELOW COMMENT

///there is no leak if the return type is givin a static address -> to point too


PARTNERS