Sign in to follow this  
chayanvinayak

Basic OpenGL

Recommended Posts

chayanvinayak    100
Hello,
I am trying to draw a very basic OpenGL program which is supposed to draw a point on the screen. But it is not drawing anything.
Following is the code.

Thanks



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


void handleResize(int w, int h){
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45,double(w)/double(h),1, 100 );
}

void handleKeypress(unsigned char key,int x, int y){
switch(key){
case 27:
exit(0);
}

}
void init(){
glEnable(GL_DEPTH_TEST);
}

void drawScene(){
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glBegin(GL_POINTS);
glVertex3f(10.0f, 20.0f, -5.1f);
glVertex3f(50.0f, 50.0f, 5.1f);
glEnd();

glBegin(GL_QUADS);
glVertex3f(10.0f, 20.0f, -5.0f);
glVertex3f(50.0f, -50.0f, 5.1f);
glVertex3f(-10.0f, 20.0f, -5.1f);
glVertex3f(-50.0f, -50.0f, 5.1f);
glEnd();

glutSwapBuffers();

}

void main (int argc, char** argv){

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH);
glutInitWindowSize(400,400);

glutCreateWindow("Chayan Vinayak's OpenGL tutorial ");
init();

glutDisplayFunc(drawScene);
glutKeyboardFunc(handleKeypress);
glutReshapeFunc(handleResize);
glutMainLoop();

}

Share this post


Link to post
Share on other sites
zacaj    667
Although the depths passed to gluPerspective are positive, the openGL view created looks down the negative axis. So -z is in front of you. You should still be getting something though. Ill try to get GLUT running and see if anything jumps out

Share this post


Link to post
Share on other sites
zacaj    667
It seems youre just drawing stuff too big. The screen should by default be black, with anything you draw being white. If you remove your QUAD code, and center your point, it will draw fine. If it doesnt, youve got a computer specific problem. This code works fine for me:
[code]void drawScene(){
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glBegin(GL_POINTS);
glVertex3f(0.0f, 0.0f, -5.1f);
glVertex3f(0.0f, 0.0f, 5.1f);
glEnd();

glutSwapBuffers();

}
[/code]

Share this post


Link to post
Share on other sites
wonderer    102
hi here is a good tutorial for the beginners

http://xoax.net/comp/cpp/opengl/

or you can take tutorial from this site as well to start with

http://www.videotutorialsrock.com/index.php

if you still can't get please post here i will help you out

Share this post


Link to post
Share on other sites
Jacob Jingle    226
Here is another good tutorial site for learning modern OpenGL:
[url="http://www.opengl-tutorial.org/"]http://www.opengl-tutorial.org/[/url]

And here is an online Book:
[url="http://www.arcsynthesis.org/gltut/index.html"]Learning Modern 3D Graphics Programming[/url]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this