steave
steave

Reputation: 395

Simple glfw draw point with opengl shows nothing

I can see the screen has been cleared to red,but no point in the center of the screen,any way here is the full code:

#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();
}

compiled using:

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.

if I compile it use gluPerspective( 65.0, (double)1024/(double)768, 1.0, 60.0 ); still the same,no point in the center of the screen,I use this makefile to compile it:

#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

Upvotes: 1

Views: 3781

Answers (1)

genpfault
genpfault

Reputation: 52166

You need a glLoadIdentity() before glOrtho().

glOrtho() doesn't set the current matrix, it multiplies by it. So set the current matrix to a known-good value (the identity matrix, via glLoadIdentity()) before calling it.

Upvotes: 1

Related Questions