我有一个GL_QUADS
来自书本的例子,我扔了一个黑色的,但我仍然不明白,我得到的只是我的清晰的白色屏幕可能是什么问题?
#include "SDL.h"
#include "SDL_opengl.h"
#include <iostream>
int main(int argc, char* args[])
{
// Memory usage specifics
SDL_Init(SDL_INIT_EVERYTHING);
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 );
SDL_GL_SetAttribute( SDL_GL_BUFFER_SIZE, 32 );
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
// name on the window
SDL_WM_SetCaption( "our first game", NULL );
//set screen
SDL_SetVideoMode(600,400,32, SDL_OPENGL);
// when screen is clear
glClearColor(1,1,1,1); //red, green, blue, alpha
//portion to display
glViewport(0,0,600,400);
//shade
glShadeModel(GL_SMOOTH);
// 3D or 2D
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); //saves
//if only 2D?
glDisable(GL_DEPTH_TEST);
//this handles the main loop
bool isRunning = true;
//this is for the events
SDL_Event event;
//main rectangle
float myX = 300;
float myY = 350;
float width = 50;
float height = 30;
//main loop
while ( isRunning )
{
//EVENTS
while ( SDL_PollEvent(&event) )
{
//logic that should happen for certain events
//quiting the window
if ( event.type == SDL_QUIT )
{
isRunning = false;
}
// if ESC pressed
if ( event.type == SDL_KEYUP && event.key.keysym.sym == SDLK_ESCAPE )
{
isRunning = false;
}
}
//LOGIC
//RENDERING TO THE SCREEN
glClear(GL_COLOR_BUFFER_BIT);
//start rendering phase
glPushMatrix();
//set the matix
glOrtho(0,600,400,0,-1,1);
//black color
glColor4ub(0,0,0,255);
//drawing
//GL_QUADS, GL_POINTS, GL_LINES, GL_LINE_STRIP,
//GL_LINE_LOOP, GL_QUADS, GL_TRIANGLES, GL_POLIGON
glBegin(GL_QUADS);
glVertex2f(myX,myY);
glVertex2f(myX+width,myY);
glVertex2f(myX+width,myY+height);
glVertex2f(myX,myY+height);
glEnd();
//render
SDL_GL_SwapBuffers();
}
//house keeping
SDL_Quit();
return 0;
}