Issues with the color comand in OpenGL









up vote
1
down vote

favorite












#include <GL/glut.h>
#include <stdio.h>

const int posicao=28.0;/*esta constante sera usada para fixar a posicao do inicio do texto para a funcao de escrita*/

float VERTICAL=30.0, HORIZ=30.0;

int seletor=1;

char escolha_de_magias="?1-Copia de Criatura: Faz uma replica perfeita de qualquer"/* criatura contra a qual voce esteja lutando. A replica tera os mesmos poderes do orignal, mas estara sob seu controle@2-Percepcao Extra-Sensorial: Sintoniza ondas psiquicas. Isso podera ajuda-lo a ler a mente de uma criatura ou descobrir o que esta por tras de uma porta trancada. Mas este encanto pode dar informacoes equivokdas, se houver + de a font psikica perto de uma outra.@3-Fogo: Tds as criaturas tm medo d fogo, e ste enknto da o podr d fazr aparecr fogo o sua vontad. Vc pdera causr a pkena xplosao n chao q keimara pr varios os ou criar a brreira d fogo p mantr criaturas a dstancia.@4-Ouro dos Tolos: Trnsforma pdra comum em a plha do q parece sr ouro. Mas eh apnas a ilusao - embora + confiavl q o Enknto d ilusao abaixo - e a plha d ouro logo voltara a sr pdra.@5-Ilusao: Ste e enknto podroso, mas q n e mto confiavl. Prmit criar a ilusao convncnte (pr exemplo, q o chao sta cobrto d krvao em brasa) p enganr a criatura. O enknto fikra imediatamnt sm efeito s acontcr qlqr coisa q dsfaca a ilusao (pr exemplo, vc convnc a criatura q s trnsformou em a serpnt e entao imediatamnt atnge sua kbca c golp d spada!). e efcient sbre td c criaturas intlignts.@6-Levitacao: Vc pde lancr ste enknto sbre objtos, advrsarios ou ate sbre si msm. Fara cm q tdo q estja sob sua influencia flutue livremnt no ar, sob o seu cntrole.@7-Escudo: Cria um scudo invsivl à sua frent q o protgera d objtos fsicos, cm flechas, spadas ou criaturas. O scudo n tm efeito cntra a magia e, evdntmnte, s nd fora dle pod tokr em vc, vc tbm n podra tokr em nd fora dle.@8-Sorte: Este enknto e spcial pq pod sr lancado a qlqr momnto durante a sua avntura, a n sr durant a batalha. a vz lancado, recuperara o seu indce d SORTE em metad d seu indce d SORTE Inicial, arredondado p baixo. Ste enknto nunk lvara o seu indce d SORTE a nmro suprior a seu nivl Inicial.@9-Habilidade: Restabelecera o seu indce d HABILIDADE. Funciona exatamnt cm o enknto d Sort.@10-Energia: Recuperara o seu indce d Energia, aumentando-o em metad d seu vlr Inicial. Funciona cmo o enknto d Sort@11-Forca: Ste enknto tm o efeito d aumentr mto a sua frca, e e mto utl qnd s luta cntra criaturas forts. Porm, dv sr utlizado c cautla, ja q e dfcil controlr a sua prpria frca qnd ela aumnta d+@12-Fraqueza: N tm efeito cntra tds as criatras, ms qnd tm, a criatra s trna fragl e mto mnos prigosa em a btalha"*/;

void escritoura (char *p)/* FUNCAO QUE ESCREVE NA TELA. Esta pronta mas sujeita a mudanças*/

int contcarac=0, position=posicao, selecao=0;
float cor[4]= 0.0, 0.0, 0.0, 0.0;
p++;
glRasterPos2f(-28.0, position);
while(*p)
*p=='0')/* testa se eu estou olhando para um algarismo*/

/*if(*(p+1)!='1' && *(p+1)!='2' && *(p+1)!='3' && *(p+1)!='4' && *(p+1)!='5' && *(p+1)!='6' && *(p+1)!='7' && *(p+1)!='8' && *(p+1)!='9' && *(p+1)!='0')/*testa se o proximo nao e um algarismo*/

glColor3d(1.0, 0.0, 0.0);


glutBitmapCharacter(GLUT_BITMAP_8_BY_13, *p);
p++;
contcarac++;

return;


void ABACAXI()

glClearColor(1.0,1.0,1.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(HORIZ-60.0, HORIZ, VERTICAL-60.0, VERTICAL,1,100);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -5.0);

glColor3d(0.0, 1.0, 0.0);

glBegin(GL_LINE_STRIP);
glVertex3d(-30.0, -30.0, 0.0);
glVertex3d(-30.0, 30.0, 0.0);
glVertex3d(30.0, 30.0, 0.0);
glVertex3d(30.0, -30.0, 0.0);
glEnd();

escritoura(escolha_de_magias);

glFlush();


void teclado(int tecla, int x, int y)

switch(tecla)

case GLUT_KEY_UP:
VERTICAL++;
break;

case GLUT_KEY_DOWN:
VERTICAL--;
break;

case GLUT_KEY_RIGHT:
HORIZ++;
break;

case GLUT_KEY_LEFT:
HORIZ--;
break;

glutPostRedisplay();


int main(int argc, char **argv)

glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE


The code ahead is supposed to draw the text in escolha_de_magias in red, but keeps drawing it in green.

I made a test with glGetFloatv(GET_CURRENT_COLOR, cor) function right before the first calling of glutBitmapCharacter() and it returned that the color of drawing is set to red.



I don't know whats happening










share|improve this question























  • Are you sure the call to set the color to red is executing? It looks like it should do that for the 2nd character in your string, but if it's not, then you probably want to step through with the debugger and see why that line isn't executing. Also you should probably call glGetError() to see if anything's going wrong with GL state.
    – user1118321
    Nov 11 at 2:20











  • While it probably won't fix your issue, you should call glColor3f instead of glColor3d. Doubles are rarely needed in computer graphics.
    – SurvivalMachine
    Nov 11 at 6:37














up vote
1
down vote

favorite












#include <GL/glut.h>
#include <stdio.h>

const int posicao=28.0;/*esta constante sera usada para fixar a posicao do inicio do texto para a funcao de escrita*/

float VERTICAL=30.0, HORIZ=30.0;

int seletor=1;

char escolha_de_magias="?1-Copia de Criatura: Faz uma replica perfeita de qualquer"/* criatura contra a qual voce esteja lutando. A replica tera os mesmos poderes do orignal, mas estara sob seu controle@2-Percepcao Extra-Sensorial: Sintoniza ondas psiquicas. Isso podera ajuda-lo a ler a mente de uma criatura ou descobrir o que esta por tras de uma porta trancada. Mas este encanto pode dar informacoes equivokdas, se houver + de a font psikica perto de uma outra.@3-Fogo: Tds as criaturas tm medo d fogo, e ste enknto da o podr d fazr aparecr fogo o sua vontad. Vc pdera causr a pkena xplosao n chao q keimara pr varios os ou criar a brreira d fogo p mantr criaturas a dstancia.@4-Ouro dos Tolos: Trnsforma pdra comum em a plha do q parece sr ouro. Mas eh apnas a ilusao - embora + confiavl q o Enknto d ilusao abaixo - e a plha d ouro logo voltara a sr pdra.@5-Ilusao: Ste e enknto podroso, mas q n e mto confiavl. Prmit criar a ilusao convncnte (pr exemplo, q o chao sta cobrto d krvao em brasa) p enganr a criatura. O enknto fikra imediatamnt sm efeito s acontcr qlqr coisa q dsfaca a ilusao (pr exemplo, vc convnc a criatura q s trnsformou em a serpnt e entao imediatamnt atnge sua kbca c golp d spada!). e efcient sbre td c criaturas intlignts.@6-Levitacao: Vc pde lancr ste enknto sbre objtos, advrsarios ou ate sbre si msm. Fara cm q tdo q estja sob sua influencia flutue livremnt no ar, sob o seu cntrole.@7-Escudo: Cria um scudo invsivl à sua frent q o protgera d objtos fsicos, cm flechas, spadas ou criaturas. O scudo n tm efeito cntra a magia e, evdntmnte, s nd fora dle pod tokr em vc, vc tbm n podra tokr em nd fora dle.@8-Sorte: Este enknto e spcial pq pod sr lancado a qlqr momnto durante a sua avntura, a n sr durant a batalha. a vz lancado, recuperara o seu indce d SORTE em metad d seu indce d SORTE Inicial, arredondado p baixo. Ste enknto nunk lvara o seu indce d SORTE a nmro suprior a seu nivl Inicial.@9-Habilidade: Restabelecera o seu indce d HABILIDADE. Funciona exatamnt cm o enknto d Sort.@10-Energia: Recuperara o seu indce d Energia, aumentando-o em metad d seu vlr Inicial. Funciona cmo o enknto d Sort@11-Forca: Ste enknto tm o efeito d aumentr mto a sua frca, e e mto utl qnd s luta cntra criaturas forts. Porm, dv sr utlizado c cautla, ja q e dfcil controlr a sua prpria frca qnd ela aumnta d+@12-Fraqueza: N tm efeito cntra tds as criatras, ms qnd tm, a criatra s trna fragl e mto mnos prigosa em a btalha"*/;

void escritoura (char *p)/* FUNCAO QUE ESCREVE NA TELA. Esta pronta mas sujeita a mudanças*/

int contcarac=0, position=posicao, selecao=0;
float cor[4]= 0.0, 0.0, 0.0, 0.0;
p++;
glRasterPos2f(-28.0, position);
while(*p)
*p=='0')/* testa se eu estou olhando para um algarismo*/

/*if(*(p+1)!='1' && *(p+1)!='2' && *(p+1)!='3' && *(p+1)!='4' && *(p+1)!='5' && *(p+1)!='6' && *(p+1)!='7' && *(p+1)!='8' && *(p+1)!='9' && *(p+1)!='0')/*testa se o proximo nao e um algarismo*/

glColor3d(1.0, 0.0, 0.0);


glutBitmapCharacter(GLUT_BITMAP_8_BY_13, *p);
p++;
contcarac++;

return;


void ABACAXI()

glClearColor(1.0,1.0,1.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(HORIZ-60.0, HORIZ, VERTICAL-60.0, VERTICAL,1,100);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -5.0);

glColor3d(0.0, 1.0, 0.0);

glBegin(GL_LINE_STRIP);
glVertex3d(-30.0, -30.0, 0.0);
glVertex3d(-30.0, 30.0, 0.0);
glVertex3d(30.0, 30.0, 0.0);
glVertex3d(30.0, -30.0, 0.0);
glEnd();

escritoura(escolha_de_magias);

glFlush();


void teclado(int tecla, int x, int y)

switch(tecla)

case GLUT_KEY_UP:
VERTICAL++;
break;

case GLUT_KEY_DOWN:
VERTICAL--;
break;

case GLUT_KEY_RIGHT:
HORIZ++;
break;

case GLUT_KEY_LEFT:
HORIZ--;
break;

glutPostRedisplay();


int main(int argc, char **argv)

glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE


The code ahead is supposed to draw the text in escolha_de_magias in red, but keeps drawing it in green.

I made a test with glGetFloatv(GET_CURRENT_COLOR, cor) function right before the first calling of glutBitmapCharacter() and it returned that the color of drawing is set to red.



I don't know whats happening










share|improve this question























  • Are you sure the call to set the color to red is executing? It looks like it should do that for the 2nd character in your string, but if it's not, then you probably want to step through with the debugger and see why that line isn't executing. Also you should probably call glGetError() to see if anything's going wrong with GL state.
    – user1118321
    Nov 11 at 2:20











  • While it probably won't fix your issue, you should call glColor3f instead of glColor3d. Doubles are rarely needed in computer graphics.
    – SurvivalMachine
    Nov 11 at 6:37












up vote
1
down vote

favorite









up vote
1
down vote

favorite











#include <GL/glut.h>
#include <stdio.h>

const int posicao=28.0;/*esta constante sera usada para fixar a posicao do inicio do texto para a funcao de escrita*/

float VERTICAL=30.0, HORIZ=30.0;

int seletor=1;

char escolha_de_magias="?1-Copia de Criatura: Faz uma replica perfeita de qualquer"/* criatura contra a qual voce esteja lutando. A replica tera os mesmos poderes do orignal, mas estara sob seu controle@2-Percepcao Extra-Sensorial: Sintoniza ondas psiquicas. Isso podera ajuda-lo a ler a mente de uma criatura ou descobrir o que esta por tras de uma porta trancada. Mas este encanto pode dar informacoes equivokdas, se houver + de a font psikica perto de uma outra.@3-Fogo: Tds as criaturas tm medo d fogo, e ste enknto da o podr d fazr aparecr fogo o sua vontad. Vc pdera causr a pkena xplosao n chao q keimara pr varios os ou criar a brreira d fogo p mantr criaturas a dstancia.@4-Ouro dos Tolos: Trnsforma pdra comum em a plha do q parece sr ouro. Mas eh apnas a ilusao - embora + confiavl q o Enknto d ilusao abaixo - e a plha d ouro logo voltara a sr pdra.@5-Ilusao: Ste e enknto podroso, mas q n e mto confiavl. Prmit criar a ilusao convncnte (pr exemplo, q o chao sta cobrto d krvao em brasa) p enganr a criatura. O enknto fikra imediatamnt sm efeito s acontcr qlqr coisa q dsfaca a ilusao (pr exemplo, vc convnc a criatura q s trnsformou em a serpnt e entao imediatamnt atnge sua kbca c golp d spada!). e efcient sbre td c criaturas intlignts.@6-Levitacao: Vc pde lancr ste enknto sbre objtos, advrsarios ou ate sbre si msm. Fara cm q tdo q estja sob sua influencia flutue livremnt no ar, sob o seu cntrole.@7-Escudo: Cria um scudo invsivl à sua frent q o protgera d objtos fsicos, cm flechas, spadas ou criaturas. O scudo n tm efeito cntra a magia e, evdntmnte, s nd fora dle pod tokr em vc, vc tbm n podra tokr em nd fora dle.@8-Sorte: Este enknto e spcial pq pod sr lancado a qlqr momnto durante a sua avntura, a n sr durant a batalha. a vz lancado, recuperara o seu indce d SORTE em metad d seu indce d SORTE Inicial, arredondado p baixo. Ste enknto nunk lvara o seu indce d SORTE a nmro suprior a seu nivl Inicial.@9-Habilidade: Restabelecera o seu indce d HABILIDADE. Funciona exatamnt cm o enknto d Sort.@10-Energia: Recuperara o seu indce d Energia, aumentando-o em metad d seu vlr Inicial. Funciona cmo o enknto d Sort@11-Forca: Ste enknto tm o efeito d aumentr mto a sua frca, e e mto utl qnd s luta cntra criaturas forts. Porm, dv sr utlizado c cautla, ja q e dfcil controlr a sua prpria frca qnd ela aumnta d+@12-Fraqueza: N tm efeito cntra tds as criatras, ms qnd tm, a criatra s trna fragl e mto mnos prigosa em a btalha"*/;

void escritoura (char *p)/* FUNCAO QUE ESCREVE NA TELA. Esta pronta mas sujeita a mudanças*/

int contcarac=0, position=posicao, selecao=0;
float cor[4]= 0.0, 0.0, 0.0, 0.0;
p++;
glRasterPos2f(-28.0, position);
while(*p)
*p=='0')/* testa se eu estou olhando para um algarismo*/

/*if(*(p+1)!='1' && *(p+1)!='2' && *(p+1)!='3' && *(p+1)!='4' && *(p+1)!='5' && *(p+1)!='6' && *(p+1)!='7' && *(p+1)!='8' && *(p+1)!='9' && *(p+1)!='0')/*testa se o proximo nao e um algarismo*/

glColor3d(1.0, 0.0, 0.0);


glutBitmapCharacter(GLUT_BITMAP_8_BY_13, *p);
p++;
contcarac++;

return;


void ABACAXI()

glClearColor(1.0,1.0,1.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(HORIZ-60.0, HORIZ, VERTICAL-60.0, VERTICAL,1,100);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -5.0);

glColor3d(0.0, 1.0, 0.0);

glBegin(GL_LINE_STRIP);
glVertex3d(-30.0, -30.0, 0.0);
glVertex3d(-30.0, 30.0, 0.0);
glVertex3d(30.0, 30.0, 0.0);
glVertex3d(30.0, -30.0, 0.0);
glEnd();

escritoura(escolha_de_magias);

glFlush();


void teclado(int tecla, int x, int y)

switch(tecla)

case GLUT_KEY_UP:
VERTICAL++;
break;

case GLUT_KEY_DOWN:
VERTICAL--;
break;

case GLUT_KEY_RIGHT:
HORIZ++;
break;

case GLUT_KEY_LEFT:
HORIZ--;
break;

glutPostRedisplay();


int main(int argc, char **argv)

glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE


The code ahead is supposed to draw the text in escolha_de_magias in red, but keeps drawing it in green.

I made a test with glGetFloatv(GET_CURRENT_COLOR, cor) function right before the first calling of glutBitmapCharacter() and it returned that the color of drawing is set to red.



I don't know whats happening










share|improve this question















#include <GL/glut.h>
#include <stdio.h>

const int posicao=28.0;/*esta constante sera usada para fixar a posicao do inicio do texto para a funcao de escrita*/

float VERTICAL=30.0, HORIZ=30.0;

int seletor=1;

char escolha_de_magias="?1-Copia de Criatura: Faz uma replica perfeita de qualquer"/* criatura contra a qual voce esteja lutando. A replica tera os mesmos poderes do orignal, mas estara sob seu controle@2-Percepcao Extra-Sensorial: Sintoniza ondas psiquicas. Isso podera ajuda-lo a ler a mente de uma criatura ou descobrir o que esta por tras de uma porta trancada. Mas este encanto pode dar informacoes equivokdas, se houver + de a font psikica perto de uma outra.@3-Fogo: Tds as criaturas tm medo d fogo, e ste enknto da o podr d fazr aparecr fogo o sua vontad. Vc pdera causr a pkena xplosao n chao q keimara pr varios os ou criar a brreira d fogo p mantr criaturas a dstancia.@4-Ouro dos Tolos: Trnsforma pdra comum em a plha do q parece sr ouro. Mas eh apnas a ilusao - embora + confiavl q o Enknto d ilusao abaixo - e a plha d ouro logo voltara a sr pdra.@5-Ilusao: Ste e enknto podroso, mas q n e mto confiavl. Prmit criar a ilusao convncnte (pr exemplo, q o chao sta cobrto d krvao em brasa) p enganr a criatura. O enknto fikra imediatamnt sm efeito s acontcr qlqr coisa q dsfaca a ilusao (pr exemplo, vc convnc a criatura q s trnsformou em a serpnt e entao imediatamnt atnge sua kbca c golp d spada!). e efcient sbre td c criaturas intlignts.@6-Levitacao: Vc pde lancr ste enknto sbre objtos, advrsarios ou ate sbre si msm. Fara cm q tdo q estja sob sua influencia flutue livremnt no ar, sob o seu cntrole.@7-Escudo: Cria um scudo invsivl à sua frent q o protgera d objtos fsicos, cm flechas, spadas ou criaturas. O scudo n tm efeito cntra a magia e, evdntmnte, s nd fora dle pod tokr em vc, vc tbm n podra tokr em nd fora dle.@8-Sorte: Este enknto e spcial pq pod sr lancado a qlqr momnto durante a sua avntura, a n sr durant a batalha. a vz lancado, recuperara o seu indce d SORTE em metad d seu indce d SORTE Inicial, arredondado p baixo. Ste enknto nunk lvara o seu indce d SORTE a nmro suprior a seu nivl Inicial.@9-Habilidade: Restabelecera o seu indce d HABILIDADE. Funciona exatamnt cm o enknto d Sort.@10-Energia: Recuperara o seu indce d Energia, aumentando-o em metad d seu vlr Inicial. Funciona cmo o enknto d Sort@11-Forca: Ste enknto tm o efeito d aumentr mto a sua frca, e e mto utl qnd s luta cntra criaturas forts. Porm, dv sr utlizado c cautla, ja q e dfcil controlr a sua prpria frca qnd ela aumnta d+@12-Fraqueza: N tm efeito cntra tds as criatras, ms qnd tm, a criatra s trna fragl e mto mnos prigosa em a btalha"*/;

void escritoura (char *p)/* FUNCAO QUE ESCREVE NA TELA. Esta pronta mas sujeita a mudanças*/

int contcarac=0, position=posicao, selecao=0;
float cor[4]= 0.0, 0.0, 0.0, 0.0;
p++;
glRasterPos2f(-28.0, position);
while(*p)
*p=='0')/* testa se eu estou olhando para um algarismo*/

/*if(*(p+1)!='1' && *(p+1)!='2' && *(p+1)!='3' && *(p+1)!='4' && *(p+1)!='5' && *(p+1)!='6' && *(p+1)!='7' && *(p+1)!='8' && *(p+1)!='9' && *(p+1)!='0')/*testa se o proximo nao e um algarismo*/

glColor3d(1.0, 0.0, 0.0);


glutBitmapCharacter(GLUT_BITMAP_8_BY_13, *p);
p++;
contcarac++;

return;


void ABACAXI()

glClearColor(1.0,1.0,1.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(HORIZ-60.0, HORIZ, VERTICAL-60.0, VERTICAL,1,100);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -5.0);

glColor3d(0.0, 1.0, 0.0);

glBegin(GL_LINE_STRIP);
glVertex3d(-30.0, -30.0, 0.0);
glVertex3d(-30.0, 30.0, 0.0);
glVertex3d(30.0, 30.0, 0.0);
glVertex3d(30.0, -30.0, 0.0);
glEnd();

escritoura(escolha_de_magias);

glFlush();


void teclado(int tecla, int x, int y)

switch(tecla)

case GLUT_KEY_UP:
VERTICAL++;
break;

case GLUT_KEY_DOWN:
VERTICAL--;
break;

case GLUT_KEY_RIGHT:
HORIZ++;
break;

case GLUT_KEY_LEFT:
HORIZ--;
break;

glutPostRedisplay();


int main(int argc, char **argv)

glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE


The code ahead is supposed to draw the text in escolha_de_magias in red, but keeps drawing it in green.

I made a test with glGetFloatv(GET_CURRENT_COLOR, cor) function right before the first calling of glutBitmapCharacter() and it returned that the color of drawing is set to red.



I don't know whats happening







opengl






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 9:30









Rabbid76

30.6k112842




30.6k112842










asked Nov 11 at 1:59









Cícero Augusto

84




84











  • Are you sure the call to set the color to red is executing? It looks like it should do that for the 2nd character in your string, but if it's not, then you probably want to step through with the debugger and see why that line isn't executing. Also you should probably call glGetError() to see if anything's going wrong with GL state.
    – user1118321
    Nov 11 at 2:20











  • While it probably won't fix your issue, you should call glColor3f instead of glColor3d. Doubles are rarely needed in computer graphics.
    – SurvivalMachine
    Nov 11 at 6:37
















  • Are you sure the call to set the color to red is executing? It looks like it should do that for the 2nd character in your string, but if it's not, then you probably want to step through with the debugger and see why that line isn't executing. Also you should probably call glGetError() to see if anything's going wrong with GL state.
    – user1118321
    Nov 11 at 2:20











  • While it probably won't fix your issue, you should call glColor3f instead of glColor3d. Doubles are rarely needed in computer graphics.
    – SurvivalMachine
    Nov 11 at 6:37















Are you sure the call to set the color to red is executing? It looks like it should do that for the 2nd character in your string, but if it's not, then you probably want to step through with the debugger and see why that line isn't executing. Also you should probably call glGetError() to see if anything's going wrong with GL state.
– user1118321
Nov 11 at 2:20





Are you sure the call to set the color to red is executing? It looks like it should do that for the 2nd character in your string, but if it's not, then you probably want to step through with the debugger and see why that line isn't executing. Also you should probably call glGetError() to see if anything's going wrong with GL state.
– user1118321
Nov 11 at 2:20













While it probably won't fix your issue, you should call glColor3f instead of glColor3d. Doubles are rarely needed in computer graphics.
– SurvivalMachine
Nov 11 at 6:37




While it probably won't fix your issue, you should call glColor3f instead of glColor3d. Doubles are rarely needed in computer graphics.
– SurvivalMachine
Nov 11 at 6:37












1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted










The color which is use for drawing characters by glutBitmapCharacter is set by glRasterPos. glRasterPos takes the current color set by glColor and associates it.



You have to se the the red color before glRasterPos2f, to draw a red text.



glColor3d(1.0, 0.0, 0.0);
glRasterPos2f(-28.0, position);


Your text appears in green, because the last color set before the call of glRasterPos2f, was the color for the GL_LINE_STRIP primitive.



If you want to draw a text with different colors, then you have to do multiple calls to glRasterPos at every point when the color of the text changes.




The current raster position can be get by glGetFloatv using the parameter GL_CURRENT_RASTER_POSITION:



float pos[4];
glGetFloatv( GL_CURRENT_RASTER_POSITION, pos );


Sadly you may not get the position which you have set by glRasterPos, because the coordinates which are passed to glRasterPos are transformed by the current model view matrix and projection matrix, but when you read back the position, then you will get the transformed coordinates and the coordinates are window coordinates rather than normalized device coordinates.




If you want to change the associated color, but to keep the raster position, then you have to read the raster current position glGetFloatv(GL_CURRENT_RASTER_POSITION, ...).

This will return window coordinates.

So you have to set an orthographic projection, which transforms from window coordinates to normalized device coordinates, before glRasterPos can be called again to associate a new color. the model view matrix has to be the identity matrix.



Change the function escritoura somehow as follows, to solve your issue:



void escritoura (char *p)

int contcarac=0, position=posicao, selecao=0;
p++;
glRasterPos2f(-28.0f, position);
while(*p)

return;






share|improve this answer






















  • @user1118321 , yes, I am. As I said in the post, I used glGetFloatv with GET_CURRENT_COLOR to get the color set right before the drawing of the first character, and if it returned the values corresponding to color red, it should break out of the loop before without drawing anything, and so it did.
    – Cícero Augusto
    Nov 11 at 14:42











  • @SurvivalMachine, I tried it too, done nothing. But thanks anyway
    – Cícero Augusto
    Nov 11 at 14:43











  • gonna try it, thnks
    – Cícero Augusto
    Nov 11 at 14:43










  • I got it, I was justifying how I got sure the color comand was being executed. Didn't tried your code yet cause I'm still studying it and trying to understand what each comand is doing. But, again. thank you
    – Cícero Augusto
    Nov 12 at 3:22











  • @CíceroAugusto You're welcome.
    – Rabbid76
    Nov 12 at 5:47










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245206%2fissues-with-the-color-comand-in-opengl%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote



accepted










The color which is use for drawing characters by glutBitmapCharacter is set by glRasterPos. glRasterPos takes the current color set by glColor and associates it.



You have to se the the red color before glRasterPos2f, to draw a red text.



glColor3d(1.0, 0.0, 0.0);
glRasterPos2f(-28.0, position);


Your text appears in green, because the last color set before the call of glRasterPos2f, was the color for the GL_LINE_STRIP primitive.



If you want to draw a text with different colors, then you have to do multiple calls to glRasterPos at every point when the color of the text changes.




The current raster position can be get by glGetFloatv using the parameter GL_CURRENT_RASTER_POSITION:



float pos[4];
glGetFloatv( GL_CURRENT_RASTER_POSITION, pos );


Sadly you may not get the position which you have set by glRasterPos, because the coordinates which are passed to glRasterPos are transformed by the current model view matrix and projection matrix, but when you read back the position, then you will get the transformed coordinates and the coordinates are window coordinates rather than normalized device coordinates.




If you want to change the associated color, but to keep the raster position, then you have to read the raster current position glGetFloatv(GL_CURRENT_RASTER_POSITION, ...).

This will return window coordinates.

So you have to set an orthographic projection, which transforms from window coordinates to normalized device coordinates, before glRasterPos can be called again to associate a new color. the model view matrix has to be the identity matrix.



Change the function escritoura somehow as follows, to solve your issue:



void escritoura (char *p)

int contcarac=0, position=posicao, selecao=0;
p++;
glRasterPos2f(-28.0f, position);
while(*p)

return;






share|improve this answer






















  • @user1118321 , yes, I am. As I said in the post, I used glGetFloatv with GET_CURRENT_COLOR to get the color set right before the drawing of the first character, and if it returned the values corresponding to color red, it should break out of the loop before without drawing anything, and so it did.
    – Cícero Augusto
    Nov 11 at 14:42











  • @SurvivalMachine, I tried it too, done nothing. But thanks anyway
    – Cícero Augusto
    Nov 11 at 14:43











  • gonna try it, thnks
    – Cícero Augusto
    Nov 11 at 14:43










  • I got it, I was justifying how I got sure the color comand was being executed. Didn't tried your code yet cause I'm still studying it and trying to understand what each comand is doing. But, again. thank you
    – Cícero Augusto
    Nov 12 at 3:22











  • @CíceroAugusto You're welcome.
    – Rabbid76
    Nov 12 at 5:47














up vote
3
down vote



accepted










The color which is use for drawing characters by glutBitmapCharacter is set by glRasterPos. glRasterPos takes the current color set by glColor and associates it.



You have to se the the red color before glRasterPos2f, to draw a red text.



glColor3d(1.0, 0.0, 0.0);
glRasterPos2f(-28.0, position);


Your text appears in green, because the last color set before the call of glRasterPos2f, was the color for the GL_LINE_STRIP primitive.



If you want to draw a text with different colors, then you have to do multiple calls to glRasterPos at every point when the color of the text changes.




The current raster position can be get by glGetFloatv using the parameter GL_CURRENT_RASTER_POSITION:



float pos[4];
glGetFloatv( GL_CURRENT_RASTER_POSITION, pos );


Sadly you may not get the position which you have set by glRasterPos, because the coordinates which are passed to glRasterPos are transformed by the current model view matrix and projection matrix, but when you read back the position, then you will get the transformed coordinates and the coordinates are window coordinates rather than normalized device coordinates.




If you want to change the associated color, but to keep the raster position, then you have to read the raster current position glGetFloatv(GL_CURRENT_RASTER_POSITION, ...).

This will return window coordinates.

So you have to set an orthographic projection, which transforms from window coordinates to normalized device coordinates, before glRasterPos can be called again to associate a new color. the model view matrix has to be the identity matrix.



Change the function escritoura somehow as follows, to solve your issue:



void escritoura (char *p)

int contcarac=0, position=posicao, selecao=0;
p++;
glRasterPos2f(-28.0f, position);
while(*p)

return;






share|improve this answer






















  • @user1118321 , yes, I am. As I said in the post, I used glGetFloatv with GET_CURRENT_COLOR to get the color set right before the drawing of the first character, and if it returned the values corresponding to color red, it should break out of the loop before without drawing anything, and so it did.
    – Cícero Augusto
    Nov 11 at 14:42











  • @SurvivalMachine, I tried it too, done nothing. But thanks anyway
    – Cícero Augusto
    Nov 11 at 14:43











  • gonna try it, thnks
    – Cícero Augusto
    Nov 11 at 14:43










  • I got it, I was justifying how I got sure the color comand was being executed. Didn't tried your code yet cause I'm still studying it and trying to understand what each comand is doing. But, again. thank you
    – Cícero Augusto
    Nov 12 at 3:22











  • @CíceroAugusto You're welcome.
    – Rabbid76
    Nov 12 at 5:47












up vote
3
down vote



accepted







up vote
3
down vote



accepted






The color which is use for drawing characters by glutBitmapCharacter is set by glRasterPos. glRasterPos takes the current color set by glColor and associates it.



You have to se the the red color before glRasterPos2f, to draw a red text.



glColor3d(1.0, 0.0, 0.0);
glRasterPos2f(-28.0, position);


Your text appears in green, because the last color set before the call of glRasterPos2f, was the color for the GL_LINE_STRIP primitive.



If you want to draw a text with different colors, then you have to do multiple calls to glRasterPos at every point when the color of the text changes.




The current raster position can be get by glGetFloatv using the parameter GL_CURRENT_RASTER_POSITION:



float pos[4];
glGetFloatv( GL_CURRENT_RASTER_POSITION, pos );


Sadly you may not get the position which you have set by glRasterPos, because the coordinates which are passed to glRasterPos are transformed by the current model view matrix and projection matrix, but when you read back the position, then you will get the transformed coordinates and the coordinates are window coordinates rather than normalized device coordinates.




If you want to change the associated color, but to keep the raster position, then you have to read the raster current position glGetFloatv(GL_CURRENT_RASTER_POSITION, ...).

This will return window coordinates.

So you have to set an orthographic projection, which transforms from window coordinates to normalized device coordinates, before glRasterPos can be called again to associate a new color. the model view matrix has to be the identity matrix.



Change the function escritoura somehow as follows, to solve your issue:



void escritoura (char *p)

int contcarac=0, position=posicao, selecao=0;
p++;
glRasterPos2f(-28.0f, position);
while(*p)

return;






share|improve this answer














The color which is use for drawing characters by glutBitmapCharacter is set by glRasterPos. glRasterPos takes the current color set by glColor and associates it.



You have to se the the red color before glRasterPos2f, to draw a red text.



glColor3d(1.0, 0.0, 0.0);
glRasterPos2f(-28.0, position);


Your text appears in green, because the last color set before the call of glRasterPos2f, was the color for the GL_LINE_STRIP primitive.



If you want to draw a text with different colors, then you have to do multiple calls to glRasterPos at every point when the color of the text changes.




The current raster position can be get by glGetFloatv using the parameter GL_CURRENT_RASTER_POSITION:



float pos[4];
glGetFloatv( GL_CURRENT_RASTER_POSITION, pos );


Sadly you may not get the position which you have set by glRasterPos, because the coordinates which are passed to glRasterPos are transformed by the current model view matrix and projection matrix, but when you read back the position, then you will get the transformed coordinates and the coordinates are window coordinates rather than normalized device coordinates.




If you want to change the associated color, but to keep the raster position, then you have to read the raster current position glGetFloatv(GL_CURRENT_RASTER_POSITION, ...).

This will return window coordinates.

So you have to set an orthographic projection, which transforms from window coordinates to normalized device coordinates, before glRasterPos can be called again to associate a new color. the model view matrix has to be the identity matrix.



Change the function escritoura somehow as follows, to solve your issue:



void escritoura (char *p)

int contcarac=0, position=posicao, selecao=0;
p++;
glRasterPos2f(-28.0f, position);
while(*p)

return;







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 11 at 9:38

























answered Nov 11 at 8:12









Rabbid76

30.6k112842




30.6k112842











  • @user1118321 , yes, I am. As I said in the post, I used glGetFloatv with GET_CURRENT_COLOR to get the color set right before the drawing of the first character, and if it returned the values corresponding to color red, it should break out of the loop before without drawing anything, and so it did.
    – Cícero Augusto
    Nov 11 at 14:42











  • @SurvivalMachine, I tried it too, done nothing. But thanks anyway
    – Cícero Augusto
    Nov 11 at 14:43











  • gonna try it, thnks
    – Cícero Augusto
    Nov 11 at 14:43










  • I got it, I was justifying how I got sure the color comand was being executed. Didn't tried your code yet cause I'm still studying it and trying to understand what each comand is doing. But, again. thank you
    – Cícero Augusto
    Nov 12 at 3:22











  • @CíceroAugusto You're welcome.
    – Rabbid76
    Nov 12 at 5:47
















  • @user1118321 , yes, I am. As I said in the post, I used glGetFloatv with GET_CURRENT_COLOR to get the color set right before the drawing of the first character, and if it returned the values corresponding to color red, it should break out of the loop before without drawing anything, and so it did.
    – Cícero Augusto
    Nov 11 at 14:42











  • @SurvivalMachine, I tried it too, done nothing. But thanks anyway
    – Cícero Augusto
    Nov 11 at 14:43











  • gonna try it, thnks
    – Cícero Augusto
    Nov 11 at 14:43










  • I got it, I was justifying how I got sure the color comand was being executed. Didn't tried your code yet cause I'm still studying it and trying to understand what each comand is doing. But, again. thank you
    – Cícero Augusto
    Nov 12 at 3:22











  • @CíceroAugusto You're welcome.
    – Rabbid76
    Nov 12 at 5:47















@user1118321 , yes, I am. As I said in the post, I used glGetFloatv with GET_CURRENT_COLOR to get the color set right before the drawing of the first character, and if it returned the values corresponding to color red, it should break out of the loop before without drawing anything, and so it did.
– Cícero Augusto
Nov 11 at 14:42





@user1118321 , yes, I am. As I said in the post, I used glGetFloatv with GET_CURRENT_COLOR to get the color set right before the drawing of the first character, and if it returned the values corresponding to color red, it should break out of the loop before without drawing anything, and so it did.
– Cícero Augusto
Nov 11 at 14:42













@SurvivalMachine, I tried it too, done nothing. But thanks anyway
– Cícero Augusto
Nov 11 at 14:43





@SurvivalMachine, I tried it too, done nothing. But thanks anyway
– Cícero Augusto
Nov 11 at 14:43













gonna try it, thnks
– Cícero Augusto
Nov 11 at 14:43




gonna try it, thnks
– Cícero Augusto
Nov 11 at 14:43












I got it, I was justifying how I got sure the color comand was being executed. Didn't tried your code yet cause I'm still studying it and trying to understand what each comand is doing. But, again. thank you
– Cícero Augusto
Nov 12 at 3:22





I got it, I was justifying how I got sure the color comand was being executed. Didn't tried your code yet cause I'm still studying it and trying to understand what each comand is doing. But, again. thank you
– Cícero Augusto
Nov 12 at 3:22













@CíceroAugusto You're welcome.
– Rabbid76
Nov 12 at 5:47




@CíceroAugusto You're welcome.
– Rabbid76
Nov 12 at 5:47

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245206%2fissues-with-the-color-comand-in-opengl%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto