Jump to content
xisto Community
Feelay

Question About Opengl Codes.

Recommended Posts

Hey!

I've started to learn windows API programming. And I've been using OpenGL.
I am following a tutorial, But I didn't understand every comment. So I rewrote the code some times to learn it, and made my own comments. Some of the rows have the comment "What do this row do??". I would be happy, if you could explain those rows to me =), please.

And BTW: I am only on the first tutorial. When I start with the others, I am sure I will have more questions. And if someone else have a questions about OpenGl, feel free to ask them here, instead of starting a new topic :mellow:.

PS! The codes I will write here is not mine! (they come from tutorials from a site named swiftless), and I don't know if I should put them in quote tags or code tags. But If they should be in qoute tags, I am sorry.

#include <GL/gl.h>//include the gl header file#include <GL/glut.h>//Include the glut header filevoid display (void){	 glClearColor(0.0,0.5,0.9,0.8);//BG Color	 glClear (GL_COLOR_BUFFER_BIT);//What do this row do??	 glLoadIdentity();//What do this row do??	 gluLookAt(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0);//Camera Position	 glFlush();//What do this row do??	 }	 int main (int argc, char **argv){	glutInit (&argc, argv);//What do this row do??	glutInitDisplayMode (GLUT_SINGLE);//What do this row do??	glutInitWindowSize(900,900);//Window Size	glutInitWindowPosition(0,0);//Window Position	glutCreateWindow ("Feelay's Fifth;)");//Window Title	glutDisplayFunc (display); //What do this row do??	glutMainLoop();//What do this row do??	return 0; //xD What do this row do :P??}

Share this post


Link to post
Share on other sites
source code c++ openGL for carQuestion About Opengl Codes.

do you know source code c++ openGL for car's model??

if you have send to my email...Please

thanks ^^

-question by rizqi

Share this post


Link to post
Share on other sites

glClear() -> clears the buffer with the color you've set the line before. In other words, it just set the background color of your view (not the right terms to say, but easyest to understand :P )glLoadIdentity() -> it loads an identity matrix, it's what openGL uses to transform the 3D to 2D.glFlush() -> flushes the buffer (write everything to the video ram so it can be shown on the screen)glutInit (&argc, argv) -> initialization for openGL, ignore this, if it works, don't touch it :DglutInitDisplayMode (GLUT_SINGLE) -> Google GLUT_SINGLE, it'll explain what it doesglutDisplayFunc (display) -> loads the function display() which configures your openGL viewglutMainLoop() -> tells openGL that this is the main loop. openGL loops through a single function all the time, you'll understand it when you start coding objects that move :P

Share this post


Link to post
Share on other sites

I've done some OpenGL programming back in the day, so I may be able to help you with the source code provided.The display function contains calls to glClearColor, glClear, and glLoadIdentity to reset the set of coordinates and attributes that OpenGL uses to keep track of what you would like to show. OpenGL uses matrix transformations (calculations) to manipulate the coordinates that you enter through your program. For example, functionality such as scaling and rotation uses matrix transformations. There's a lot of math involved when you try to do something like that yourself and using OpenGL keeps you from having to bother with the trigonometry and matrix calculations.Whenever you build a scene through OpenGL, what you want to do is flush it so it is displayed right away at a particular point in code. Each time you draw something, you would flush and then start on the next scene. Don't expect the results to be instantaneous because rendering complex scenes would take a bit of time.OpenGL programming is a lot like Win32 programming where you have to specify everything that you want the program to do. Almost all C/C++ programs accept command line parameters to modify the behavior of the program and OpenGL can do some processing of its own, which is what happens when the glut library reads the arguments.Setting a single buffer display mode is quick and easy to work with, but when you have complex scenes, you would want to work with double buffers to avoid screen flicker. While you are practicing initially, you might want to stick with using a single buffer mode for simplicity.The glut library delegates the responsibility of displaying something on-screen to a separate function so you don't bunch everything together within the main function, which is why you specify that the display function should be called by the glut library.The main loop lets OpenGL process any input that it might receive so unless you are planning to build a scene, render it to file and quit, you ought to keep the loop in there.All C/C++ programs return a status code and the norm is to return a zero if your program exits with no errors, and to return a non-zero value with a number to represent the type of error that has occurred. This can be any number designated by you because users of the program would report back to you the status code returned by the program to ask you to figure out why it does not work.If you do need to have a more detailed explanation, feel free to ask.

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

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.