View Full Version : Creating window, initializing opengl
01-12-2011, 02:41 PM
im using VS 2010 C++ Express
I created empty project and put there window. I need that on the button press it will create the openGL window. I found the code for creating the window but it access wrong memory address. The code for create and initialize window is as usual:
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
pleas help, im new to opengl.
01-12-2011, 04:18 PM
I don't like to be rude.. but the web is full of tutorial that explain how to create a window with an openGl context.
Then when you ask for help can you please explain your problem properly? Witch line give you the segmentation fault? Can we see the call stack? Witch version of glut are you using? Windows? 64bit?
Are you using Unicode but your library don't support them?
Those four line of code are correct, so the problem must be elsewhere.
01-12-2011, 04:40 PM
Rule #1 - always, always, always, when you're trying something new for the first time, run your program in the debugger. In MSVC go to Configuration Manager, set your Active Configuration to "Debug", press Ctrl-Shift-B to build, then F5 to debug. If your program crashes it will halt on the line it crashed on and you can do lots of cool stuff like examine the values of variables, the contents of memory locations, the call stack, and other useful things.
In your case my suspicion is - like Rosario said - that your project is set up to use Unicode and that's conflicting with GLUT. Another possibility is conflicts between the Visual C++ runtime you've selected and GLUT. You should know how to modify these in your project properties - learning how to get the best use out of your IDE is a vital part of programming.
Rule #2 - you say that you're new to OpenGL, so don't try anything fancy. Your first program should be as basic as possible. Creating a new Window on a button press and setting up OpenGL in that window is something fancy; don't do this. Instead create a simple one window program that just glClears the screen, then put a triangle on it, then colour the triangle, texture it and light it if you want, and make it spin. Your first objective is to understand how OpenGL interacts with the windowing system and successfully get something on-screen, nothing more. Anything else is only going to distract you from what you need to know when starting out.
In all my years of doing OpenGL, I've never tried to do what you want to do. The closest I've come is to run a program that does some calculations, then opens a GL window. Question: are you able to open a GL window without pushing a button, i.e. by doing something basic like one of the first few NeHe Tutorials? That would be a good start, because it would tell us that you have the basic graphics correct. Then, we could concentrate on the button thing. How are you going to create a button without having a graphics window open? A button is a graphic and must be displayed in a graphics window. So maybe you are asking, if I have one window open with a button in it (another challenge), how do I open a second window when I push the button?
01-13-2011, 05:30 AM
i managed it. The problem was that i was trying initialized by glutInit() with empty arguments. Stupid i know.
Powered by vBulletin® Version 4.2.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.