Jump to content
Eternal Lands Official Forums
Florian

Q: How do I draw text?

Recommended Posts

I wanted to have a look at the eye candy effect positioning problem and I need the ID of the bone points.

 

So I added

 

for(currPoint = 0; currPoint < nrPoints; currPoint++) {
	unsigned char str[4];
	int view[4];
	sprintf((char *)str, "%3d", currPoint);
	draw_ortho_ingame_string(points[currPoint][0] + 0.02, points[currPoint][1], points[currPoint][2], str, 1, SMALL_INGAME_FONT_X_LEN, SMALL_INGAME_FONT_Y_LEN);
}

 

to cal_render_bones in cal.c.

 

The result ist this:

http://www.superfloh.dyndns.org/el/elscreen008_test.jpg

 

What did I do wrong? How can I print little numbers with the bone point IDs next to the points?

Share this post


Link to post
Share on other sites

Hmm, well, I'm a n00b with openGL, so my solution to this will probably look very very st00pid to the experienced programmers, but hey, it works :D:)

 

http://www.superfloh.dyndns.org/el/bones.jpg

http://www.superfloh.dyndns.org/el/bones.png (better quality)

 


===================================================================
RCS file: /cvsroot/elc/elc/cal.c,v
retrieving revision 1.69
diff -u -d -p -r1.69 cal.c
--- cal.c	   20 Dec 2007 19:31:28 -0000	  1.69
+++ cal.c	   24 Dec 2007 00:41:55 -0000
@@ -12,6 +12,7 @@
#include "tiles.h"
#endif /* NEW_SOUND */
#ifdef DEBUG
+#include "font.h"
#include "init.h"
#endif /* DEBUG */
#ifdef OPENGL_TRACE
@@ -24,6 +25,9 @@
 #include "lights.h"
#endif

+void draw_number_at_xyz(float x, float y, float z, int number);
+void draw_char_at_xyz(float x, float y, float z, int chr);
+
void cal_actor_set_anim_delay(int id, struct cal_anim anim, float delay)
{
	actor *pActor = actors_list[id];
@@ -277,12 +281,145 @@ void cal_render_bones(actor *act)
	}

	glEnd();
+
+	   for(currPoint = 0; currPoint < nrPoints; currPoint++) {
+			   //unsigned char str[4];
+			   //int view[4];
+			   //sprintf((char *)str, "%3d", currPoint);
+			   //draw_ortho_ingame_string(points[currPoint][0] + 0.02, points[currPoint][1], points[currPoint][2], str, 1, SMALL_INGAME_FONT_X_LEN, SMALL_INGAME_FONT_Y_LEN);
+			   draw_number_at_xyz(points[currPoint][0], points[currPoint][1], points[currPoint][2], currPoint);
+	   }
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE

}

+void draw_number_at_xyz(float x, float y, float z, int number) {
+ int num = number;
+ int chr = 0;
+ printf("draw number: %d\n", number);
+ if (num > 9) {
+  chr = num / 10;
+  draw_char_at_xyz(x, y, z, chr);
+ }
+ draw_char_at_xyz(x, y + 0.03, z, num % 10);
+}
+
+void draw_char_at_xyz(float x, float y, float z, int chr) {
+ glLineWidth(2.0f);
+ glColor3f(0.0f, 1.0f, 0.0f);
+ switch (chr) {
+  case 0:
+   printf(" draw char: %d\n", chr);
+   glBegin(GL_LINE_STRIP);
+	glVertex3f(x, y, z);
+	glVertex3f(x, y, z + 0.04);
+	glVertex3f(x, y - 0.02, z + 0.04);
+	glVertex3f(x, y - 0.02, z);
+	glVertex3f(x, y, z);
+   glEnd();
+   break;
+  case 1:
+   printf(" draw char: %d\n", chr);
+   glBegin(GL_LINES);
+	glVertex3f(x, y, z);
+	glVertex3f(x, y, z + 0.04);
+   glEnd();
+   break;
+  case 2:
+   printf(" draw char: %d\n", chr);
+   glBegin(GL_LINE_STRIP);
+	glVertex3f(x, y, z);
+	glVertex3f(x, y - 0.02, z);
+	glVertex3f(x, y - 0.02, z + 0.02);
+	glVertex3f(x, y, z + 0.02);
+	glVertex3f(x, y, z + 0.04);
+	glVertex3f(x, y - 0.02, z + 0.04);
+   glEnd();
+   break;
+  case 3:
+   printf(" draw char: %d\n", chr);
+   glBegin(GL_LINE_STRIP);
+	glVertex3f(x, y - 0.02, z);
+	glVertex3f(x, y, z);
+	glVertex3f(x, y, z + 0.02);
+	glVertex3f(x, y - 0.02, z + 0.02);
+	glVertex3f(x, y, z + 0.02);
+	glVertex3f(x, y, z + 0.04);
+	glVertex3f(x, y - 0.02, z + 0.04);
+   glEnd();
+   break;
+  case 4:
+   printf(" draw char: %d\n", chr);
+   glBegin(GL_LINE_STRIP);
+	glVertex3f(x, y - 0.02, z + 0.04);
+	glVertex3f(x, y - 0.02, z + 0.02);
+	glVertex3f(x, y, z + 0.02);
+   glEnd();
+   glBegin(GL_LINES);
+	glVertex3f(x, y, z);
+	glVertex3f(x, y, z + 0.04);
+   glEnd();
+   break;
+  case 5:
+   printf(" draw char: %d\n", chr);
+   glBegin(GL_LINE_STRIP);
+	glVertex3f(x, y - 0.02, z);
+	glVertex3f(x, y, z);
+	glVertex3f(x, y, z + 0.02);
+	glVertex3f(x, y - 0.02, z + 0.02);
+	glVertex3f(x, y - 0.02, z + 0.04);
+	glVertex3f(x, y, z + 0.04);
+   glEnd();
+   break;
+  case 6:
+   printf(" draw char: %d\n", chr);
+   glBegin(GL_LINE_STRIP);
+	glVertex3f(x, y, z + 0.04);
+	glVertex3f(x, y - 0.02, z + 0.04);
+	glVertex3f(x, y - 0.02, z);
+	glVertex3f(x, y, z);
+	glVertex3f(x, y, z + 0.02);
+	glVertex3f(x, y - 0.02, z + 0.02);
+   glEnd();
+   break;
+  case 7:
+   printf(" draw char: %d\n", chr);
+   glBegin(GL_LINE_STRIP);
+	glVertex3f(x, y - 0.02, z + 0.04);
+	glVertex3f(x, y, z + 0.04);
+	glVertex3f(x, y, z);
+   glEnd();
+   break;
+  case 8:
+   printf(" draw char: %d\n", chr);
+   glBegin(GL_LINE_STRIP);
+	glVertex3f(x, y, z);
+	glVertex3f(x, y, z + 0.04);
+	glVertex3f(x, y - 0.02, z + 0.04);
+	glVertex3f(x, y - 0.02, z);
+	glVertex3f(x, y, z);
+   glEnd();
+   glBegin(GL_LINES);
+	glVertex3f(x, y, z + 0.02);
+	glVertex3f(x, y - 0.02, z + 0.02);
+   glEnd();
+   break;
+  case 9:
+   printf(" draw char: %d\n", chr);
+   glBegin(GL_LINE_STRIP);
+	glVertex3f(x, y, z + 0.02);
+	glVertex3f(x, y - 0.02, z + 0.02);
+	glVertex3f(x, y - 0.02, z + 0.04);
+	glVertex3f(x, y, z + 0.04);
+	glVertex3f(x, y, z);
+   glEnd();
+   break;
+  default:
+   break;
+ }
+}

__inline__ void render_submesh(int meshId, int submeshCount, struct CalRenderer * pCalRenderer, float meshVertices[30000][3], float meshNormals[30000][3], float meshTextureCoordinates[30000][2], CalIndex meshFaces[50000][3])
{

Share this post


Link to post
Share on other sites

Hmm, well, I'm a n00b with openGL, so my solution to this will probably look very very st00pid to the experienced programmers, but hey, it works :) :)

I'm the openGL n00b, those pics great and very funny at the same time. I've a copy of "OpenGL programming guide" on loan that I intend to dip into over my Christmas break. I'm not expecting to get far but when you're starting from nothing its all improvement :)

Edited by bluap

Share this post


Link to post
Share on other sites

I like the workaround you found :icon13:

However, as I also need to know the bones IDs for the missiles implementation, I took a look at the problem and here's a patch corresponding to a way to do it by using fonts :)

 

Index: cal.c
===================================================================
RCS file: /cvsroot/elc/elc/cal.c,v
retrieving revision 1.69
diff -u -r1.69 cal.c
--- cal.c	   20 Dec 2007 19:31:28 -0000	  1.69
+++ cal.c	   2 Jan 2008 20:39:50 -0000
@@ -246,6 +246,12 @@
	int currLine;
	int currPoint;
	struct CalSkeleton *skel;
+	   GLdouble model[16], proj[16];
+	   GLint view[4];
+	   GLdouble px,py,pz;
+	   char buf[16];
+	   float font_size_x = SMALL_INGAME_FONT_X_LEN/ALT_INGAME_FONT_X_LEN;
+	   float font_size_y = SMALL_INGAME_FONT_Y_LEN/ALT_INGAME_FONT_X_LEN;

	skel=CalModel_GetSkeleton(act->calmodel);
	nrLines = CalSkeleton_GetBoneLines(skel,&lines[0][0][0]);
@@ -277,6 +283,40 @@
	}

	glEnd();
+
+	   glGetDoublev(GL_MODELVIEW_MATRIX, model);
+	   glGetDoublev(GL_PROJECTION_MATRIX, proj);
+	   glGetIntegerv(GL_VIEWPORT, view);
+
+	   glPushMatrix();
+	   glLoadIdentity();
+	   glMatrixMode(GL_PROJECTION);
+	   glPushMatrix();
+	   glLoadIdentity();
+
+	   glOrtho(view[0],view[2]+view[0],view[1],view[3]+view[1],0.0f,-1.0f);
+
+	   glPushAttrib(GL_ENABLE_BIT);
+
+	   glEnable(GL_TEXTURE_2D);
+	   glEnable(GL_BLEND);
+	   glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
+
+	   glColor4f(1.0, 0.0, 0.0, 1.0);
+
+	   for (currPoint = 0; currPoint < nrPoints; currPoint++) {
+			   sprintf(buf, "%d", currPoint);
+			   gluProject(points[currPoint][0], points[currPoint][1], points[currPoint][2], model, proj, view, &px, &py, &pz);
+			   draw_ortho_ingame_string(px, py, pz, buf, 1, font_size_x, font_size_y);
+	   }
+
+	   glPopAttrib();
+
+	   glMatrixMode(GL_PROJECTION);
+	   glPopMatrix();
+	   glMatrixMode(GL_MODELVIEW);
+	   glPopMatrix();
+
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×