Advertisement

[Solved] Lesson 43

Started by November 30, 2009 03:05 AM
5 comments, last by tre 14 years, 11 months ago
Having problems displaying text with lesson 43. And I didn't get the information about "zlib1.dll" either. When I try to output text nothing displays. Here's my draw function:
void draw(void){
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

	glColor3f(1.0f, 1.0f, 1.0f);
	glPushMatrix();
		glLoadIdentity();
		glTranslatef(0, 0, -5);
		freetype::print(our_font, 320, 200, "This is a test\whee");
	glPopMatrix();


	glTranslatef(0.0f, 0.0f, -13.0f);

	RotateScene(EYE_RADIUS, RotateCamY, RotateCamX, 180.0);

	lighting();

	quadricsSettings();

	drawGlobe(4.0f, 100);

	drawStars(200.0f, 10);

	glFlush();
}

Am I doing something wrong? I want white text displayed in my OpenGL window. I haven't positioned it yet but I want it in the top right corner of the screen later. Why am I seeing nothing? I'm not getting any errors on the code and the rest of my program works just as it should. After some looking around I found out that the zlib1.dll that was missing was supposed to go into the project folder. Thanks for the GREAT tutorials! Marcus Axelsson Edit: I got an error here
// in file: freetype.cpp
const char *start_line = text;
vector<string> lines;
for(const char *c = text; *c; c++){
	if(*c == '\n'){
		string line;
		for(const char *n = start_line; n < c; n++){
			line.append(1, *n);
		}
		lines.push_back(line);
		start_line = c + 1;
	}
}
if(start_line){
	string line;
	for(const char *n = start_line; n < c; n++){
		line.append(1, *n);
	}
	lines.push_back(line);
}

error C2065: 'c' : undeclared identifier I solved that by adding const char *c = text; Beneath vector<string> lines;. I also get a lot of conversion and trucation warnings as well as one signed/unsigned mismatch. I guess the warnings doesn't really matter that much. But there it is. And I still can't get the text to show :) [Edited by - tre on December 2, 2009 5:22:15 PM]
Allright. Text is showing now... but I can't color it. It's black whatever I do, and I need it to be a light blue.

void drawText(void){	glBindTexture(GL_TEXTURE_2D, 0);	glDisable(GL_LIGHTING);	glDisable(GL_TEXTURE_2D);	shader.unbind();	glColor3f(0.0f, 1.0f, 0.0f);	glPushMatrix();		glLoadIdentity();		freetype::print(our_font, 320, 200, "This is a text\nthat contains a break");	glPopMatrix();	shader.bind();	glEnable(GL_TEXTURE_2D);	glEnable(GL_LIGHTING);}void draw(void){	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	glLoadIdentity();	glTranslatef(0.0f, 0.0f, -20.0f);	RotateScene(EYE_RADIUS, RotateCamY, RotateCamX, 180.0);	lighting();	quadricsSettings();	drawGlobe(4.0f, 100);	drawStars(200.0f, 10);	drawText();	glFlush();}


Any takers? :)

Edit:
And \n doesn't take. No new lines.
Advertisement
This subject is now solved by going with an alternative to Lesson 43, the "hacked" version available on the errata page for the lesson.
It still took some pushing and prodding to get this code to work. But here's the thread:
http://www.gamedev.net/community/forums/topic.asp?topic_id=554887

The code I'm using now (and is presented in the thread above) has it's own problems. For one it rotates with the camera (which should be easy to fix) and it can't handle newlines, which will be a bit more difficult to fix.

Thanks!
This is a compiler issue. These lines :
const char *start_line = text;vector<string> lines;for(const char *c = text; *c; c++){	if(*c == '\n'){		string line;		for(const char *n = start_line; n < c; n++){			line.append(1, *n);		}		lines.push_back(line);		start_line = c + 1;	}}if(start_line){	string line;	for(const char *n = start_line; n < c; n++){		line.append(1, *n);	}	lines.push_back(line);}

will compile with MSVC6 compiler because the 'const char *c' declared in the first 'for' statement will be visible after the end of this statement, so it will be visible in the next 'for' statement which uses it. However, this is not a correct compiler behavior. Any other compiler will not accept it.

Unfortunately, many programmers started with MSVC6 and wrote wrong code using this hack, and trying to compile such programs will recent decent compiler definitely result in an error.
Quote: Original post by vincoof
This is a compiler issue. These lines :
*** Source Snippet Removed ***
will compile with MSVC6 compiler because the 'const char *c' declared in the first 'for' statement will be visible after the end of this statement, so it will be visible in the next 'for' statement which uses it. However, this is not a correct compiler behavior. Any other compiler will not accept it.

Unfortunately, many programmers started with MSVC6 and wrote wrong code using this hack, and trying to compile such programs will recent decent compiler definitely result in an error.

Thank you for clearing this up. I thought it looked very, very, very wrong and I understand why it doesn't compile.
I don't know how to fix it, though :)
Quote: Original post by tre
I don't know how to fix it, though :)

Instead of beginning like this :
const char *start_line = text;vector<string> lines;for(const char *c = text; *c; c++){

Begin like this :
const char *start_line = text;vector<string> lines;const char *c;for(c = text; *c; c++){

This roughly makes what MSVC6 compiler does but compatible for all compilers (including MSVC6).
Advertisement
Quote: Original post by vincoof
Quote: Original post by tre
I don't know how to fix it, though :)

Instead of beginning like this :
*** Source Snippet Removed ***
Begin like this :
*** Source Snippet Removed ***
This roughly makes what MSVC6 compiler does but compatible for all compilers (including MSVC6).


Thank you very much :)

This topic is closed to new replies.

Advertisement