Problem using Nehe BaseCode v2
Hi there !
I started learning OpenGL yesterday, and I wanted to use directly the Nehe BaseCode v2 with lesson 02 ("my first triangle and quad" tutorial)
So I took the code from DrawGL...() in lesson 2, and put it inside the Draw() function in the basecode, after the original code. So in theory, i would obtain a triangle, a quad and some text.
All compile well, I run the exe and... the triangle and the quad don''t appear.
I tried to move code from the initGL..()function of lesson2 to initGL...() in the base code or in the draw code, nothing change
I surely miss something but I can''t figure out where I went wrong.
Please help !!
PS. I''ve just thought that maybe I put my triangle and quad at a location the camera can''t reach. If this is the right guess, where should I draw them ? For now I just copy/pasted the code
(Now I''m at the office so I can''t try this)
And many thanks in advance (^o^)
----
David Sporn AKA Sporniket
----David Sporn AKA SporniketThe blog of the Sporniket(in French) | Sporniket-Studio.com, my gallery of poster (via zazzle.com) | Sanctuaire Tokugawa, free Japanese lesson (in French)
Now I ''m back to home and could play/test with the code. It turns out to be that setting things up to create the GLFont then prevents tutorial code to work properly. Now all works fine (^o^)
More especially, here is the modified code :
BOOL Initialize (GL_Window* window, Keys* keys) // Any GL Init Code & User Initialiazation Goes Here
{
g_window = window;
g_keys = keys;
// Start Of User Initialization
angle = 0.0f; // Set Starting Angle To Zero
/*
Texs[0]=auxDIBImageLoad("Data/font1.bmp"); // Load Font Texture
glGenTextures(1, &texture[0]); // Create Font Texture
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, Texs[0]->sizeX , Texs[0]->sizeY , 0, GL_RGB, GL_UNSIGNED_BYTE, Texs[0]->data);
if(Texs[0]->data != NULL) free(Texs[0]->data); // Free Data Allocated
// Set Font Texture, How Many Characters per row and how many columns
fNehe.SetTexture(texture[0],16,16);
// Set Font Width and Font Height in Texture, and Character Spacing
fNehe.SetFontProperties(16,16,10);
// Adjust Fonts 2D Drawing Rectangle Size
fNehe.SetDisplayMode(window->init.width,window->init.height);
fNehe.BuildFont(); // Build The Font
*/
glClearColor (0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth (1.0f); // Depth Buffer Setup
glDepthFunc (GL_LEQUAL); // The Type Of Depth Testing (Less Or Equal)
glEnable (GL_DEPTH_TEST); // Enable Depth Testing
glShadeModel (GL_SMOOTH); // Select Smooth Shading
glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Set Perspective Calculations To Most Accurate
glBlendFunc(GL_SRC_ALPHA,GL_ONE); // Enable Blending
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
glEnable(GL_BLEND); // Enable Blending
return TRUE; // Return TRUE (Initialization Successful)
}
void Draw (void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The View
glPushMatrix();
glTranslatef(-1.5f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0
glBegin(GL_TRIANGLES); // Drawing Using Triangles
glVertex3f( 0.0f, 1.0f, 0.0f); // Top
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glEnd(); // Finished Drawing The Triangle
glTranslatef(3.0f,0.0f,0.0f); // Move Right 3 Units
glBegin(GL_QUADS); // Draw A Quad
glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glEnd(); // Done Drawing The Quad
/*
float r = (float)(angle / 200.0f);
while (r > 1.0f) {
r -= 1.0f;
}
glColor3f(r,0.3f,1.0f);
fNehe.SetBase(32); // Adjust Base Start Pos (First Set of Fonts)
fNehe.Print(20,30,"NeHe Productions Presents:"); // Print GL Text To The Screen
glColor3f(1.0f,1.0f,0.0f);
fNehe.SetBase(32 - 128); // Adjust Base Start Pos (Second Set of Fonts)
fNehe.Print(20,50,"Tutorial"); // Print GL Text To The Screen
glPopMatrix();
*/
glFlush (); // Flush The GL Rendering Pipeline
}
Now I will try to figure out what happened.
Anyway I''m soooooooooooo happy now, I draw my very first openGL Triangle and Quad !! (^o^)
I''ll be back...
----
David Sporn AKA Sporniket
More especially, here is the modified code :
BOOL Initialize (GL_Window* window, Keys* keys) // Any GL Init Code & User Initialiazation Goes Here
{
g_window = window;
g_keys = keys;
// Start Of User Initialization
angle = 0.0f; // Set Starting Angle To Zero
/*
Texs[0]=auxDIBImageLoad("Data/font1.bmp"); // Load Font Texture
glGenTextures(1, &texture[0]); // Create Font Texture
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, Texs[0]->sizeX , Texs[0]->sizeY , 0, GL_RGB, GL_UNSIGNED_BYTE, Texs[0]->data);
if(Texs[0]->data != NULL) free(Texs[0]->data); // Free Data Allocated
// Set Font Texture, How Many Characters per row and how many columns
fNehe.SetTexture(texture[0],16,16);
// Set Font Width and Font Height in Texture, and Character Spacing
fNehe.SetFontProperties(16,16,10);
// Adjust Fonts 2D Drawing Rectangle Size
fNehe.SetDisplayMode(window->init.width,window->init.height);
fNehe.BuildFont(); // Build The Font
*/
glClearColor (0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth (1.0f); // Depth Buffer Setup
glDepthFunc (GL_LEQUAL); // The Type Of Depth Testing (Less Or Equal)
glEnable (GL_DEPTH_TEST); // Enable Depth Testing
glShadeModel (GL_SMOOTH); // Select Smooth Shading
glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Set Perspective Calculations To Most Accurate
glBlendFunc(GL_SRC_ALPHA,GL_ONE); // Enable Blending
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
glEnable(GL_BLEND); // Enable Blending
return TRUE; // Return TRUE (Initialization Successful)
}
void Draw (void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The View
glPushMatrix();
glTranslatef(-1.5f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0
glBegin(GL_TRIANGLES); // Drawing Using Triangles
glVertex3f( 0.0f, 1.0f, 0.0f); // Top
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glEnd(); // Finished Drawing The Triangle
glTranslatef(3.0f,0.0f,0.0f); // Move Right 3 Units
glBegin(GL_QUADS); // Draw A Quad
glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glEnd(); // Done Drawing The Quad
/*
float r = (float)(angle / 200.0f);
while (r > 1.0f) {
r -= 1.0f;
}
glColor3f(r,0.3f,1.0f);
fNehe.SetBase(32); // Adjust Base Start Pos (First Set of Fonts)
fNehe.Print(20,30,"NeHe Productions Presents:"); // Print GL Text To The Screen
glColor3f(1.0f,1.0f,0.0f);
fNehe.SetBase(32 - 128); // Adjust Base Start Pos (Second Set of Fonts)
fNehe.Print(20,50,"Tutorial"); // Print GL Text To The Screen
glPopMatrix();
*/
glFlush (); // Flush The GL Rendering Pipeline
}
Now I will try to figure out what happened.
Anyway I''m soooooooooooo happy now, I draw my very first openGL Triangle and Quad !! (^o^)
I''ll be back...
----
David Sporn AKA Sporniket
----David Sporn AKA SporniketThe blog of the Sporniket(in French) | Sporniket-Studio.com, my gallery of poster (via zazzle.com) | Sanctuaire Tokugawa, free Japanese lesson (in French)
Finally, I could understand what happened !!
In fact, the GLFont creates and use a texture object, so when drawing after a call to BuildFont or Print of the GLFont class,
the active texture remains active
So, before begining your drawing just put a line like this :
glBindTexture(GL_TEXTURE_2D,0) ;
This one set the standard texture (plain color) as the active texture.
Ok, now I''m going to leçon 3....
Happy OpenGL-ing !
----
David Sporn AKA Sporniket
In fact, the GLFont creates and use a texture object, so when drawing after a call to BuildFont or Print of the GLFont class,
the active texture remains active
So, before begining your drawing just put a line like this :
glBindTexture(GL_TEXTURE_2D,0) ;
This one set the standard texture (plain color) as the active texture.
Ok, now I''m going to leçon 3....
Happy OpenGL-ing !
----
David Sporn AKA Sporniket
----David Sporn AKA SporniketThe blog of the Sporniket(in French) | Sporniket-Studio.com, my gallery of poster (via zazzle.com) | Sanctuaire Tokugawa, free Japanese lesson (in French)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement