Here´s my code. I use SDL_TTF and it worked before. Later on i added lighting and materials, and textures to my scene, and this started to be black for the first time.
But anyways, disabling or enabling them, even glColorMaterial, i get a black surface on the screen. What??. I tried to raise the effect of the ambient light ... maybe it had relation with materials, or something. But nothing happens.
Sorry for the explanations. They are in spanish.
//============================================================
void Vista::dibujarTexto(){
// obtengo los valores de GL_Viewport
int vPort[4];
glGetIntegerv(GL_VIEWPORT, vPort);
// guardo la matriz de proyeccion para ponerla a identidad
// y establezco la proyeccion a ortografica con los datos de GL_Viewport
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, vPort[2], 0, vPort[3], -1, 1);
// establezco a la identidad la matriz de modelado vista
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
// desactivo cosas que pueden afectar a la visibilidad
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glDisable(GL_COLOR_MATERIAL);
// Creo un color y una posicion
SDL_Color color;
color.r = 255;
color.g = 255;
color.b = 255;
// (origen abajo a la izquierda).
// renderizo todos los trozos de texto
SDL_Rect position;
position.x = 10;
position.y = _altoVentana - 35;
renderTexto("RATON y CLICKS rotar y mover -- FLECHAS: deslizar -- NORMALES Y RELLENO: q,w -- PUERTA: g", _fuente, color, &position);
position.y -= position.h;
renderTexto("VISTAS: oblicua i, ortogonal o, perspectiva p. lateral 4, frontal 5, cenital 6, esquina 7.", _fuente, color, &position);
position.y -= position.h;
renderTexto("Luz global: l -- luz focal: k -- luz direccional: j -- niebla: h -- SALIR: Esc o Espacio", _fuente, color, &position);
position.y -= position.h;
renderTexto("Mover lampara: z x -- Escalar lampara: a s -- SALIR: Esc o Espacio", _fuente, color, &position);
// muestra los fps
char str[222];
sprintf(str, "FPS: %f", _fps);
position.y -= position.h;
renderTexto(str, _fuente, color, &position);
// enciendo todo como estaba
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
}
//============================================================
void Vista::renderTexto(std::string text,TTF_Font *font,SDL_Color color,
SDL_Rect *const location)
{
// uso SDL_TTF para renderizar el texto en una superficie
const char* text_C = text.c_str();
SDL_Surface *initial = TTF_RenderText_Blended(font, text_C, color);
// convierto el texto a un formato conocido, potencia de 2
int w = round(pow(2,ceil(log(initial->w) / log(2))));
int h = round(pow(2,ceil(log(initial->h) / log(2))));
// creo una superficie RGB intermediaria
SDL_Surface *intermediary = SDL_CreateRGBSurface(0, w, h, 32,
0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
// pego la inicial con el texto sobre la intermedia que es la base
SDL_BlitSurface(initial, 0, intermediary, 0);
// creo la textura
GLuint texture = 0;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, 4, w, h, 0, GL_BGRA,
GL_UNSIGNED_BYTE, intermediary->pixels );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// dibujo los cuadrados
glColor3f(0.0f,0.0f,0.0f);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 1.0f);
glVertex2f(location->x , location->y);
glTexCoord2f(1.0f, 1.0f);
glVertex2f(location->x + w, location->y);
glTexCoord2f(1.0f, 0.0f);
glVertex2f(location->x + w, location->y + h);
glTexCoord2f(0.0f, 0.0f);
glVertex2f(location->x , location->y + h);
glEnd();
//glFinish();
location->w = initial->w;
location->h = initial->h;
// libero los recursos.
SDL_FreeSurface(initial);
SDL_FreeSurface(intermediary);
glDeleteTextures(1, &texture);
}