dev.gamez.lv Forum Index dev.gamez.lv
Latvian Game Developers Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups 

GLFW print text
Goto page 1, 2, 3  Next
 
dev.gamez.lv Forum Index -> Iesācējiem
View previous topic :: View next topic  
Author Message
tiy



Joined: 12 Jan 2007
Posts: 28

PostPosted: Sat Mar 03, 2007 2:20 am    Post subject: GLFW print text

It ka visu nokompile, taisiju pec nehere 13 lesson. Tomer nevaru saprast kapec vush nedruka to tekstu ara, liku BuildFont(); visur tapatas nav?

Code:
#include <windows.h> 
#include <stdio.h>   
#include <GL\glfw.h>   
#include <gl\glaux.h>
#include <math.h>     
#include <stdarg.h>   


HDC        hDC=NULL; 
HGLRC      hRC=NULL; 
HWND       hWnd=NULL;
HINSTANCE  hInstance;


GLuint  base;     
GLfloat  cnt1;     
GLfloat  cnt2;     

 

bool  keys[256];     
bool  active=TRUE;   
bool  fullscreen=TRUE;
LRESULT  CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); 

GLvoid BuildFont(GLvoid) 
{
  HFONT  font;           
  base = glGenLists(96); 

    font = CreateFont(  -24,       
                          0,       
                          0,       
                          0,       
                          FW_BOLD,     
                          FALSE,       
                          FALSE,       
                          FALSE,       
                          ANSI_CHARSET,     
                          OUT_TT_PRECIS,     
                          CLIP_DEFAULT_PRECIS,   
                          ANTIALIASED_QUALITY,   
                          FF_DONTCARE|DEFAULT_PITCH, 
                          "Courier New");     
                           SelectObject(hDC, font);       
 wglUseFontBitmaps(hDC, 32, 96, base);
}


GLvoid KillFont(GLvoid)           
{
   glDeleteLists(base, 96);       
}


GLvoid glPrint(const char *fmt, ...)       
{
char    text[256];     
  va_list    ap;         
  if (fmt == NULL)     
    return;             

  va_start(ap, fmt);           
  vsprintf(text, fmt, ap); 
  va_end(ap);                   
  glPushAttrib(GL_LIST_BIT);       

  glListBase(base - 32);         
  glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
  glPopAttrib(); 

 
 
int DrawGLScene(GLvoid) 
{
  //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 // glLoadIdentity(); 
  //glTranslatef(0.0f,0.0f,-1.0f);
   
  glColor3f(1.0f*float(cos(cnt1)),1.0f*float(sin(cnt2)),1.0f-0.5f*float(cos(cnt1+cnt2)));
 
  glRasterPos2f(-0.45f+0.05f*float(cos(cnt1)), 0.35f*float(sin(cnt2)));
  glPrint("Active OpenGL Text With NeHe - %7.2f", cnt1); 
   cnt1+=0.051f;   
  cnt2+=0.005f; 
  return TRUE;   
}
 
//----------------------------------------------------------------------
// Draw() - Main OpenGL drawing function that is called each frame
//----------------------------------------------------------------------
void Draw( void )
{
    int    width, height;  // Window dimensions
    double t;              // Time (in seconds)

    // Get current time
    t = glfwGetTime();

    // Get window size
    glfwGetWindowSize( &width, &height );

    // Make sure that height is non-zero to avoid division by zero
    height = height < 1 ? 1 : height;

    // Set viewport
    glViewport( 0, 0, width, height );

    // Clear color and depht buffers
    glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
       
   
    // Set up projection matrix
    glMatrixMode( GL_PROJECTION );    // Select projection matrix
    glLoadIdentity();                 // Start with an identity matrix
    gluPerspective(                   // Set perspective view
        65.0,                         // Field of view = 65 degrees
        (double)width/(double)height, // Window aspect (assumes square pixels)
        1.0,                          // Near Z clipping plane
        100.0                         // Far Z clippling plane
    );

    // Set up modelview matrix
    glMatrixMode( GL_MODELVIEW );     // Select modelview matrix
    glLoadIdentity();                 // Start with an identity matrix
    gluLookAt(                        // Set camera position and orientation
        0.0, 0.0, 10.0,               // Camera position (x,y,z)
        0.0, 0.0, 0.0,                // View point (x,y,z)
        0.0, 1.0, 0.0                 // Up-vector (x,y,z)
    );
 
//  glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
  BuildFont();           
 
 
      //glRotatef( 60.0f * (float)t, 0.0f, 1.0f, 0.0f ); // Rotate the triangle about the y-axis

    if( glfwGetKey( GLFW_KEY_SPACE ) ){
         glBegin( GL_LINES );
             GLfloat color [] ={0.0, 8.0, 0.0};
             glColor3fv( color );   
             glVertex3f( 0.0f, 6.5f, 0.0f );                       
             glVertex3f( 0.0f, -6.5f, 0.0f);
             glVertex3f( 8.5f, 0.0f, 0.0f );                       
             glVertex3f( -8.5f, 0.0f, 0.0f);
         glEnd();
    }
   
     DrawGLScene();
 
}
 

//----------------------------------------------------------------------
// main() - Program entry point
//----------------------------------------------------------------------
int main( int argc, char **argv )
{   
    int    ok;             // karogs kas saka ka logs ir atveries
    int    running;        // karogs kas saka ka programma strada

    glfwInit(); // Initialize GLFW
                           // Build The Font
    // Open window
    ok = glfwOpenWindow(
        640, 480,          // Width and height of window
        8, 8, 8,           // Number of red, green, and blue bits for color buffer
        8,                 // Number of bits for alpha buffer
        24,                // Number of bits for depth buffer (Z-buffer)
        0,                 // Number of bits for stencil buffer
        GLFW_WINDOW        // We want a desktop window (could be GLFW_FULLSCREEN)
    );
   
   
   
    if( !ok ){ // If we could not open a window, exit now
        glfwTerminate();
        return 0;
    }

    glfwSetWindowTitle( "OpenGL FrameWorks" );     // Set window title
    glfwEnable( GLFW_STICKY_KEYS ); // Enable sticky keys



    // Main rendering loop
    do
    {      
        Draw();
       
        glfwSwapBuffers(); // Swap front and back buffers (we use a double buffered display)

        // Check if the escape key was pressed, or if the window was closed
        running = !glfwGetKey( GLFW_KEY_ESC ) &&
                  glfwGetWindowParam( GLFW_OPENED );
    }
    while( running );

    glfwTerminate();  // Terminate GLFW   
    return 0; // Exit program
}
Back to top
View user's profile
Tenjou



Joined: 22 Nov 2005
Posts: 275

PostPosted: Sat Mar 03, 2007 10:35 am    Post subject:

1. BuildFont ir jataisa pirms zīmēšanas loop`a nevis katru frame atkartoti.

2. Pirms BuildFont uztaisit hDC = GetDC(hWnd);
Back to top
View user's profile
tiy



Joined: 12 Jan 2007
Posts: 28

PostPosted: Sat Mar 03, 2007 1:40 pm    Post subject:

Paldies sanaca, bet varetu paskaidrot kas ta par magisku rindunu hDC = GetDC(hWnd); dabu loga parametrus ?
Back to top
View user's profile
Tenjou



Joined: 22 Nov 2005
Posts: 275

PostPosted: Sat Mar 03, 2007 1:57 pm    Post subject:

Apmēram, iegūst tekošā loga display device contextu uz kura zimēt to fontu.
Bet tas ir vajadzīgs tikai ja izmanto Win32 API zīmēšanas funkcijas Tikai neiesaku pārak aizrauties ar šo...vienīgi ja tevi nesatrauc, kad šāds fonts nestrādās uz citām platformām.

Iesaku http://freetype.sourceforge.net/index2.html tikai diezgan nepatīkams priekš sākuma.
Back to top
View user's profile
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Sat Mar 03, 2007 3:57 pm    Post subject:

Fontiem iesaku lietot vai nu glFont2, vai arī Bitmap Font Generator. Šito pēdējo mēs izmantojām Squares 3D.
Back to top
View user's profile Send e-mail
tiy



Joined: 12 Jan 2007
Posts: 28

PostPosted: Sat Mar 03, 2007 9:17 pm    Post subject:

Kaut kas nav isti nevaru saprast kapec man fps nesrada kavajaga?
Piemera, kas bija ieksh indago tur ari f-ja atgriez int nevis ka sheit double.
Kur var but vaina?

palasiju referenci glfw tur nebija nekas lidzigs shai f-jai.
SDL_GetTicks(); //noskaidrojam shii briizja laiku


Code:

    double time;              // Time (in seconds)
    int frame=0,timebase=0;   

    frame++;
   time = glfwGetTime();  // Get current time
   if (time - timebase > 1000) {
     GLfloat color [] ={0.0, 8.0, 0.0};
     glColor3fv( color ); 
     glRasterPos2f(0.3f,6.0f);
     glPrint("FPS: %4.2f", frame*1000/(time-timebase));        
     timebase = time;      
    frame = 0;
   }
Back to top
View user's profile
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Sat Mar 03, 2007 9:32 pm    Post subject:

glfwGetTime jau arī ir analogs SDL_GetTicks fjai.

Kāpēc tu tur reizini ar 1000? glfwGetTime jau atgriež laiku sekundēs nevis milisekundēs. Tev vajag kadrus/sekundē. Tev ir frame=kadri un time-timebase=sekundes. Tātad frame/(time-timebase).

P.S. Ja prasi palīdzēt salabot kādu kļūdu, tad esi precizāks - pasaki ko esi ieguvis, kas tieši nestrādā kā vajag, kas rādās/nerādās, un tml.. Citādi jāsāk minēt un skatīties kristāla bumbā kāpēc tev "fps nesrada kavajaga?".
Back to top
View user's profile Send e-mail
tiy



Joined: 12 Jan 2007
Posts: 28

PostPosted: Sat Mar 03, 2007 9:56 pm    Post subject:

Uztaisiju ta, man sak skaitit no 0.70 un atri uz leju kamer tiek lidz 0.24 un tad pazud?
Code:

double time,timebase=0;              // Time (in seconds)
    int frame=0;


    frame++;
   time = glfwGetTime();  // Get current time
   if (time - timebase > 1) {           
     glPrint("FPS: %2.2f", frame/(time-timebase));     
     timebase = time;     
    frame = 0;
   }
Back to top
View user's profile
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Sat Mar 03, 2007 10:35 pm    Post subject:

Kā un kurā vietā tu šo kodu lieto?
Back to top
View user's profile Send e-mail
tiy



Joined: 12 Jan 2007
Posts: 28

PostPosted: Sat Mar 03, 2007 11:38 pm    Post subject:

ieksha draw f-jas, parametrus ari tur pat.

Bet laikam tas nav pareizi, iznesu lauka ka globalos, tapatas rada neparezi.


laikam ta ver apskatities man rada fps300> tas ta var but?

http://yy.lv/download.php?f=28860
Back to top
View user's profile
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Sun Mar 04, 2007 1:17 am    Post subject:

Tad iepriekš tu to frame un timebase mainīgos katru reizi inicializeji Draw fjā? Tas, portams, bija neapreizi. Tev taču vajadzēja saprast, ka frames mainīgais skaita kadrus. Kā tad var skaitīt kadrus, ja katra kadra zīmēšanā tu to uzstādi par 0.

Kāpēc tu domā ka 300fps ir nepareizi? Cik tad tu gaidīji 5fps? Man, piemēram, rāda ap 600. Tukšu ekrānu zīmējot ar dažu rasterfju izsaukumiem un ekrāna notīrīšanu vajadzētu būt ok.

Vēl vari pamēģināt ar glfw ieslēgt attēla vertikālo sinhronizāciju (ja vien tas nav diseiblots videokartes draiveros). Tad fps būtu jābūt vienāam ar monitoram uzstādītajiem herciem.
Back to top
View user's profile Send e-mail
tiy



Joined: 12 Jan 2007
Posts: 28

PostPosted: Sun Mar 04, 2007 2:07 am    Post subject:

Labi, nakama problema ir klat, nehe 6 lesson texturas ir nemtas no turienes
ir tani pasha mapite. Tomer kaut ka nesanak to texturu uzlikt man rada tikai baltu rotejoshu kubu. loadtexture nemu no wiki piemera, jo no nehe negaja (tur cita).

Cik saprotu ka glfw neatbalsta bmp tikai tag, formatus, bet pat uz tag balts kubs.


http://paste.php.lv/5253
Back to top
View user's profile
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Sun Mar 04, 2007 2:37 am    Post subject:

Manuprāt tu pats nesaproti kodu, kuru tu raksti.
Šī rinda: glfwReadImage("Data/NeHe.bmp", &image, GLFW_ORIGIN_UL_BIT);
Vai saproti, ko nozīmē "Data/NeHe.bmp" un "tekošā direktorija" kā tu pats saki?

Un par TGA formātu - tieši tā, GLFW atbalsta tikai TGA formāta bildes.

Ja rāda baltu bildi, tad vajag pārbaudīt kļūdas. Piemēram tā pati glfwReadImage atgriež integeru - GL_TRUE, ja bilde ir veiksmīgi ielādēta, vai GL_FALSE, ja nav.
Back to top
View user's profile Send e-mail
tiy



Joined: 12 Jan 2007
Posts: 28

PostPosted: Sun Mar 04, 2007 11:30 am    Post subject:

Quote:
Manuprāt tu pats nesaproti kodu, kuru tu raksti.

Ja, tieshi ta, jo ja saprastu tad neprasitu.

Palasiju referenci un pie read uzliku GLFW_BUILD_MIPMAPS_BIT, un tani dat faila iemtu tag bildi un saka stradat.

Tads jautajums, sanak ka ieksh Squares 3D, visur ari tika izmantoti tikai *.tag bildes?

Ka var reset krasam uztaisit , tas ir man ir fps izvadishana zala krasa un tad kad zime kubu un fps izvada uzliek texturi un paliek zalaka?
Back to top
View user's profile
Tenjou



Joined: 22 Nov 2005
Posts: 275

PostPosted: Sun Mar 04, 2007 12:00 pm    Post subject:

Es tev ieteiktu ja macies no nehe, tad ari vajadzetu sākt ar pirmo stundu un tā uz priekšu. Jo krāsu nomaina ar glColor3f(0.0f, 0.0f, 0.0f) tajos trīs nomaini ciparus līdz 1.0f. Ja visi būs 1.0f, tad bus balta, ja visur 0.0f, tad melna u.tt
Back to top
View user's profile
Display posts from previous:   
dev.gamez.lv Forum Index -> Iesācējiem All times are GMT + 2 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group