我可以看到屏幕已被清除为红色,但屏幕中心没有一点,这里是完整的代码:
#include "GL/glfw.h"
void render_loop()
{
glClearColor ( .7, .1, .1, 1.0f );
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glViewport(0,0,1024,768);
glMatrixMode(GL_PROJECTION);
//gluPerspective( 65.0, (double)1024/(double)768, 1.0, 60.0 );
glOrtho(0,1024,768,0,100,-100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPointSize(10);
glBegin(GL_POINTS);
glColor4f(1,1,1,1);
glVertex3f(512,384,0);
glEnd();
glfwSwapBuffers();
}
int main ( int argc, char* argv[] )
{
//init glfw
glfwInit();
glfwOpenWindow ( 1024, 768, 8, 8, 8, 8, 24, 0, GLFW_WINDOW );
do {
render_loop();
} while ( glfwGetWindowParam ( GLFW_OPENED ) );
glfwTerminate();
}
编译使用:
john@Linux:~> gcc --version
gcc (SUSE Linux) 4.7.1 20120723 [gcc-4_7-branch revision 189773]
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
如果我编译它使用gluPerspective( 65.0, (double)1024/(double)768, 1.0, 60.0 );
仍然相同,屏幕中心没有点,我使用这个 makefile 来编译它:
#makefile for example1 on linux
CC=gcc -std=c99 -Wno-unused-function -Wno-unused-variable
SRC=\
a.c \
OBJS=$(SRC:.c=.o)
NAME=testglpoints
CFLAGS = -Wall $(INCLUDE)
LFLAGS =\
-lGL \
-lglut \
-lGLU \
-lGLEW \
-ldl \
-lpthread \
-lm \
-lglfw
all: debug
debug:override CFLAGS = -g3 -O0 -Wall
debug:$(OBJS)
$(CC) $(CFLAGS) $(LFLAGS) $(SRC) -o $(NAME)
clean:
@rm -f *.o