Jump to content
  • Advertisement
Sign in to follow this  
chayanvinayak

Basic OpenGL

This topic is 2559 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
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:
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();

}

Share this post


Link to post
Share on other sites
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!