我有一个奇怪的OpenGL
问题glColor3f
。在下面的代码中,如果我改变 的红色值glColor3f
,那么下面的多边形就会变成那个红色阴影。但是,如果我改变绿色或蓝色,那么它不会改变多边形的颜色,但会改变游戏中所有其他对象的颜色。基本上,只有函数的红色值起作用,我也需要蓝色和绿色才能起作用。
glColor3f(1.0f,1.0f,0.0f);
for(int i = 0; i < totalhumans; i++)
{
if(humans[i].rage)
{
glPushMatrix();
glTranslatef(humans[i].x,humans[i].y,humans[i].depth);
glBegin(GL_QUADS);
glVertex3f(-16.0f,-(humans[i].dimen->bodyh/2)-16,0.0f);
glVertex3f(-16.0f,-(humans[i].dimen->bodyh/2)-8,0.0f);
glVertex3f(16.0f,-(humans[i].dimen->bodyh/2)-8,0.0f);
glVertex3f(16.0f,-(humans[i].dimen->bodyh/2)-16,0.0f);
glEnd();
glPopMatrix();
}
}
这是我的初始化代码:
void START_GAME()
{
SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO|SDL_INIT_TIMER);
Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT,2,2048);
SDL_ShowCursor(SDL_DISABLE);
loadsettings();
if(fullscreen)
{
const SDL_VideoInfo *VideoInfo = SDL_GetVideoInfo();
screen = SDL_SetVideoMode(VideoInfo->current_w, VideoInfo->current_h, 32, SDL_OPENGL|SDL_FULLSCREEN);
}
if(!fullscreen)
{
screen = SDL_SetVideoMode(640, 480, 32, SDL_OPENGL);
}
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
glClearColor(0.0f,0.0f,0.0f,0.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.0f);
setvariables();
loadimages();
loadsounds();
SDL_WM_SetCaption("Freshmen Stuffing Boys",NULL);
SDL_WM_SetIcon(badge,NULL);
running = true;
}
编辑:我发现由于某种原因,在禁用后GL_TEXTURE_2D
,我想要的颜色出现了。有人可以解释为什么会这样吗?
这个问题不是重复的,因为1)我的电脑是新的,所有的显卡驱动都是新的,所以不是gpu问题,2)我是第一次写代码,所以我没有想知道代码是否可以在任何其他计算机上运行。