Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Mathimetric

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

#5119601 How to get user writing input string in openGl?

Posted by Mathimetric on 27 December 2013 - 08:14 PM

quik simple example

inside  ~ MainWindowProc ~

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

 

 

example.JPG

 

 
//                                                                  //
    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')



#5041484 any fast program for reading large txt files?

Posted by Mathimetric on 10 March 2013 - 06:35 AM

//List class def

//programmer : MJO 2013'

//#include "datatype.h"

 

#include <stddef.h>

 

 

class List_
{
 
 

 typedef struct Node_
 {
  DataT_ data_;
  DataT_Key key_;
  
  Node_ *next;
  Node_ *prev;
 }Node_;

private: 

Node_ * list_;
Node_ * head_;
Node_ * tail_;
Node_ * Itorator_;

long size_;

public:
////////////////////////////////////////////////////////////////////////////////////////////////////
//construct/destruct//
List_();
~List_();
////////////////////////////////////////////////////////////////////////////////////////////////////
//stack function//
int Push(DataT_ );
DataT_  Pop();
DataT_ Top();
////////////////////////////////////////////////////////////////////////////////////////////////////
//list function//
int Insert(DataT_Key);
int Delete(DataT_Key);
////////////////////////////////////////////////////////////////////////////////////////////////////
//queue function//
int enQueue(DataT_ );
DataT_  deQueue();
////////////////////////////////////////////////////////////////////////////////////////////////////
//general function
int clear_list();
int HasNext();
int HasPrev();
Node_ * iBegin();  //return itorator_ = head
Node_ * iEnd(); //return itorator_ = tail
Node_ * gHead();
Node_ * gTail();
Node_ * gItorator();
Node_ * gNext();
Node_ * gPrev();
long  Size();
DataT_ ShowData(Node_ *);
////////////////////////////////////////////////////////////////////////////////////////////////////
};//List_ class


////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////

//construct/destruct//
List_::List_()
{
 list_ = NULL;
 head_= NULL;
 tail_= NULL;
 Itorator_= NULL;
 size_ = 0;
}

List_::~List_()
{
 clear_list();
}

long List_::Size()
{
return size_;
}

//stack function//
int List_::Push(DataT_ input_)
{
 if(list_ == NULL){ 
 //start new list
 list_ = new Node_;
 list_->next = NULL;
 list_->prev = NULL;
 //set list addressing
 head_ = list_;
 tail_ = list_;
 Itorator_ = list_;
 list_->data_ = input_;
 return ++size_; 
 //else push onto list STACK
 }else{
 head_->prev = new Node_;
 Itorator_ = head_;
 head_ = head_->prev;
 head_->next = Itorator_;
 Itorator_->prev = head_;
 head_->prev = NULL;
 head_->data_ = input_;
 return ++size_;
 } 
 
}

DataT_  List_::Pop()
{
 //pop head ,delete, fix addressing, return dataT
if(head_->next != NULL)
{
 Itorator_ = head_;
 head_ = head_->next;
 DataT_ temp_ = Itorator_->data_;
 delete Itorator_;
 head_->prev = NULL;
 --size_;
 return temp_;
}
else
{
 Itorator_ = head_; 
 DataT_ temp_ = Itorator_->data_;
 delete Itorator_;
 Itorator_ = NULL;
 head_ = NULL;
 tail_ = NULL;
 list_ = NULL;
 --size_;
 return temp_;
}

}


DataT_  List_::Top()
{
 Itorator_ = head_;
 return Itorator_->data_;

}
//list function//
int List_::Insert(DataT_Key key_in)
{
 
 return 0;

}
int List_::Delete(DataT_Key)
{
return 0;


}

//queue function//
int List_::enQueue(DataT_ input_)
{
 if(list_ == NULL){
 
 //start new list
 list_ = new Node_;
 list_->next = NULL;
 list_->prev = NULL; 
 //set list addressing
 head_ = list_;
 tail_ = list_;
 Itorator_ = list_;
 list_->data_ = input_;
 return ++size_;
 }else{

 head_->prev = new Node_;
 Itorator_ = head_;
 head_ = head_->prev;
 head_->next = Itorator_;
 Itorator_->prev = head_;
 head_->prev = NULL;
 head_->data_ = input_;
 return ++size_; 
 }
 
 


}

DataT_  List_::deQueue()
{

if(tail_->prev != NULL)
{
 Itorator_ = tail_;
 DataT_ temp_ = Itorator_->data_;
 tail_ = tail_->prev;
 delete Itorator_;
 tail_->next = NULL;
 --size_;
 return temp_;
}else{

 Itorator_ = tail_;
 DataT_ temp_ = Itorator_->data_;
 delete Itorator_;
 tail_ = NULL; 
 Itorator_ = NULL;
 head_ = NULL;
 list_ = NULL;
 --size_;
 return temp_;
}

}

List_::Node_*  List_::gHead()
{
return head_;
}

List_::Node_* List_::gTail()
{
return tail_;
}

List_::Node_* List_::gItorator()
{
return Itorator_;
}

//general function
int List_::clear_list()
{
if(head_ == NULL) return -1; //had no list
static Node_ *temp_i;
if(temp_i == NULL) temp_i = head_;

 if(temp_i->next != NULL){
 Itorator_ = temp_i;
 temp_i = temp_i->next;
 delete Itorator_;
 Itorator_ = NULL; --size_;
 clear_list(); //call to clear again
 }else{ //reached the end of the list
 delete temp_i;
 temp_i = NULL;
 head_ = NULL;
 tail_ = NULL;
 list_ = NULL;
 --size_;
 }  
return size_;//size would be zero
}


List_::Node_ * List_::iBegin()
{
return Itorator_ = head_;
}

List_::Node_ * List_::iEnd()
{
return Itorator_ = tail_;
}

List_::Node_ * List_::gNext()
{
return Itorator_ =  (Itorator_->next == NULL ? NULL : Itorator_->next );
}
List_::Node_ * List_::gPrev()
{
return Itorator_ =  (Itorator_->prev == NULL ? NULL : Itorator_->prev );
}

DataT_ List_::ShowData(List_::Node_ *in_pointer)
{
return in_pointer->data_;
}

int List_::HasNext()
{
return Itorator_->next == NULL ? 0: 1;
}
int List_::HasPrev()
{
return Itorator_->prev == NULL ? 0: 1;
}




#5041483 any fast program for reading large txt files?

Posted by Mathimetric on 10 March 2013 - 06:32 AM

#include <iostream.h>
#include <fstream.h>
#include <stddef.h>
#include <stdlib.h>

//LIST DATA TYPE DEF'S
typedef char DataT_;
typedef long DataT_Key;
///////////////////////

#include <List_.h>


using namespace std;

 

//data browser meant for opening very large resource files
//and browsing page by page for peaks and looks at the data
//for research and study of the file structure
//purpose: to dynamic load one page of 6.4k bytes of raw data
//so that memory is managed for speed and performance and not overloaded

//key data will serve as data position for bit page following
//page #

class DataBrowser
{

List_ *Page;   //80x80 bytes (6.4k/page)
fstream DataFile_;  //file stream
char * fname;  //file name

 

public:

DataBrowser();
~DataBrowser();


DataBrowser(char*); //overload construct parameter sets filename

void setfname(char*);

int openfile(char*);

void closefile();

 

int LoadPage(long);  //load by page index
   //page index = (pos 0) + (page_num * 6400)
   //returns true if the page is valid else 0

int DisplayPage(); //displays this->page if valid
   //returns true if display success;

List_ * GetPage(); //returns this->page memory address

 

}; //class DataBrowser

 

DataBrowser::DataBrowser() { Page = new List_; }
DataBrowser::~DataBrowser(){if(Page != NULL) delete Page; else return;}

DataBrowser::DataBrowser(char * f_name)
{
fname = f_name;
cout<<"\nconstructing file name: "<<this->fname;
Page = new List_;
}
 //overload construct parameter sets filename

void DataBrowser::setfname(char* f_name)
{
fname = f_name;
}

 

int DataBrowser::openfile(char* f_name)
{
DataFile_.open(f_name, ios::in | ios::ate | ios::binary);
DataFile_.seekg(0,ios::beg);
return (DataFile_.fail() ? 0 : 1);
}

void DataBrowser::closefile()
{
if(DataFile_.is_open())
{ DataFile_.close();DataFile_.clear();}
else return;
}


   //load by page index
   //page index = (pos 0) + (page_num * 6400)
   //returns true if the page is valid else 0

int DataBrowser::LoadPage(long page_num)
{  


 if(!openfile(fname)){ cout<<"\nfile read error"; closefile(); return -1;}
 else{
 
 long pos = page_num * 3200;
 long epos = pos + 3200;
 
 
 system("cls");
 cout<<"file: "<<fname;
 cout<<"\nLoading Page: "<<page_num<<endl;
 DataFile_.seekg(pos, ios::beg);
 
 

 DataT_ tmp_;
 while(!DataFile_.fail() && pos < epos)
 {
 
 DataFile_.get(tmp_);
 Page->enQueue( (tmp_ == '\a' ? 0 : tmp_) );
 pos = DataFile_.tellg();

 };
 int rtn = DataFile_.eof();
 closefile();
 if(rtn)
 return 0;
 else
 return 1;
 }
 
 

}

//displays this->page if valid
//returns true if display success

int DataBrowser::DisplayPage()
{

while(Page->gItorator() != NULL){ cout<<  Page->deQueue() ;}
return 0;

List_ * DataBrowser::GetPage(){return Page;} //returns this->page memory address


 




#5041454 Existing 3D Game Engine for Gameplay Programming

Posted by Mathimetric on 10 March 2013 - 04:23 AM

Have you thought of designing your own engine using the OpenGL library?




PARTNERS