www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Trying to get Derelict.opengl3.gl3 and derelict.glfw3.glfw3 to work

reply "csmith" <csmith.ku2013 gmail.com> writes:
Hi everyone,

I've got derelict.opengl3.gl3 and derelict.glfw3.glfw3 setup with 
dub and can get a window to open up and close with glfw3. I can 
also use glClear(GL_COLOR_BUFFER_BIT); however, beyond this most 
OpenGL commands fail and I can't seem to figure out how to fix it.

Code:

     import std.stdio;
     import derelict.opengl3.gl3, derelict.glfw3.glfw3;

     void main(string args[])
     {
         DerelictGL3.load(); // Loads OpenGL v1.0 and v1.1
         DerelictGLFW3.load(); // Loads GLFW3

         assert (glfwInit(), "Failed to initialize GLFW3");
         scope (exit) glfwTerminate();

         glfwSetErrorCallback(&error_callback);

         auto window = glfwCreateWindow(640, 480, "Simple 
example", null, null);	
         assert (window !is null);

         glfwMakeContextCurrent(window);
         auto vers = DerelictGL3.reload(); // Created GLFW3 
context, so GL3 needs to be reloaded
	
         while (!glfwWindowShouldClose(window)) {
             if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
                 glfwSetWindowShouldClose(window, GL_TRUE);
		
             glClear(GL_COLOR_BUFFER_BIT);
             glBegin(GL_POINTS);
             glEnd();
		
             glfwSwapBuffers(window);
             glfwPollEvents();
         }

         glfwDestroyWindow(window);
         glfwTerminate();
     }

     extern (C) void error_callback(int error, const(char)* 
description) nothrow {
         printf("%s %s", error, description);
     }

Compiler Output:

     derelict-util: ["derelict-util"]
     derelict-util: ["derelict-util"]
     derelict-glfw3: ["derelict-glfw3", "derelict-util"]
     derelict-util: ["derelict-util"]
     derelict-gl3: ["derelict-gl3", "derelict-util"]
     myproj: ["myproj", "derelict-util", "derelict-glfw3", 
"derelict-util", "derelict-gl3", "derelict-util"]
     Target is up to date. Using existing build in 
/home/csmith/.dub/packages/derelict-util-1.0.2/.dub/build/library-debug-linux.posix-x86_64-dmd-A741715720F146
08FFF241F87E468DD/. 
Use --force to force a rebuild.
     Target is up to date. Using existing build in 
/home/csmith/.dub/packages/derelict-glfw3-1.0.2/.dub/build/library-debug-linux.posix-x86_64-dmd-DD1819CE8266F3
0192AAD3190CA5B06/. 
Use --force to force a rebuild.
     Target is up to date. Using existing build in 
/home/csmith/.dub/packages/derelict-gl3-1.0.6/.dub/build/library-debug-linux.posix-x86_64-dmd-59B635D839F3A8
FC2737986D4B622FD/. 
Use --force to force a rebuild.
     Building myproj configuration "application", build type debug.
     Compiling...
     source/app.d(25): Error: undefined identifier glBegin
     source/app.d(26): Error: undefined identifier glEnd
     FAIL 
.dub/build/application-debug-linux.posix-x86_64-dmd-357CCD4CB91C
CEC384AF7BAA514E3A7 
myproj executable
     Error executing command run: DMD compile run failed with exit 
code 1

Any ideas?

Thanks,
Charles
Sep 23 2014
next sibling parent "kiran kumari" <kiranfabzen gmail.com> writes:
On Wednesday, 24 September 2014 at 03:08:55 UTC, csmith wrote:
 Hi everyone,

 I've got derelict.opengl3.gl3 and derelict.glfw3.glfw3 setup 
 with dub and can get a window to open up and close with glfw3. 
 I can also use glClear(GL_COLOR_BUFFER_BIT); however, beyond 
 this most OpenGL commands fail and I can't seem to figure out 
 how to fix it.

 Code:

     import std.stdio;
     import derelict.opengl3.gl3, derelict.glfw3.glfw3;

     void main(string args[])
     {
         DerelictGL3.load(); // Loads OpenGL v1.0 and v1.1
         DerelictGLFW3.load(); // Loads GLFW3

         assert (glfwInit(), "Failed to initialize GLFW3");
         scope (exit) glfwTerminate();

         glfwSetErrorCallback(&error_callback);

         auto window = glfwCreateWindow(640, 480, "Simple
see more example http://techgurulab.com/course/java-quiz-online/
 example", null, null);	
         assert (window !is null);

         glfwMakeContextCurrent(window);
         auto vers = DerelictGL3.reload(); // Created GLFW3 
 context, so GL3 needs to be reloaded
 	
         while (!glfwWindowShouldClose(window)) {
             if (glfwGetKey(window, GLFW_KEY_ESCAPE) == 
 GLFW_PRESS)
                 glfwSetWindowShouldClose(window, GL_TRUE);
 		
             glClear(GL_COLOR_BUFFER_BIT);
             glBegin(GL_POINTS);
             glEnd();
 		
             glfwSwapBuffers(window);
             glfwPollEvents();
         }

         glfwDestroyWindow(window);
         glfwTerminate();
     }

     extern (C) void error_callback(int error, const(char)* 
 description) nothrow {
         printf("%s %s", error, description);
     }

 Compiler Output:

     derelict-util: ["derelict-util"]
     derelict-util: ["derelict-util"]
     derelict-glfw3: ["derelict-glfw3", "derelict-util"]
     derelict-util: ["derelict-util"]
     derelict-gl3: ["derelict-gl3", "derelict-util"]
     myproj: ["myproj", "derelict-util", "derelict-glfw3", 
 "derelict-util", "derelict-gl3", "derelict-util"]
     Target is up to date. Using existing build in 
 /home/csmith/.dub/packages/derelict-util-1.0.2/.dub/build/library-debug-linux.posix-x86_64-dmd-A741715720F146
08FFF241F87E468DD/. 
 Use --force to force a rebuild.
     Target is up to date. Using existing build in 
 /home/csmith/.dub/packages/derelict-glfw3-1.0.2/.dub/build/library-debug-linux.posix-x86_64-dmd-DD1819CE8266F3
0192AAD3190CA5B06/. 
 Use --force to force a rebuild.
     Target is up to date. Using existing build in 
 /home/csmith/.dub/packages/derelict-gl3-1.0.6/.dub/build/library-debug-linux.posix-x86_64-dmd-59B635D839F3A8
FC2737986D4B622FD/. 
 Use --force to force a rebuild.
     Building myproj configuration "application", build type 
 debug.
     Compiling...
     source/app.d(25): Error: undefined identifier glBegin
     source/app.d(26): Error: undefined identifier glEnd
     FAIL 
 .dub/build/application-debug-linux.posix-x86_64-dmd-357CCD4CB91C
CEC384AF7BAA514E3A7 
 myproj executable
     Error executing command run: DMD compile run failed with 
 exit code 1

 Any ideas?

 Thanks,
 Charles
Sep 23 2014
prev sibling next sibling parent "Nicolas F." <ddev fratti.ch> writes:
Make sure to call DerelictGL3.reload() to get "all" the OpenGL
calls, if you don't, you only get OpenGL 1.1
Sep 24 2014
prev sibling parent reply Mike Parker <aldacron gmail.com> writes:
On 9/24/2014 12:08 PM, csmith wrote:
 Hi everyone,
      Compiling...
      source/app.d(25): Error: undefined identifier glBegin
      source/app.d(26): Error: undefined identifier glEnd
      FAIL
 .dub/build/application-debug-linux.posix-x86_64-dmd-357CCD4CB91CACEC384AF7BAA514E3A7
 myproj executable
      Error executing command run: DMD compile run failed with exit code 1

 Any ideas?
You're using deprecated OpenGL calls. The gl3 module only declares and loads modern OpenGL. If you really want to use the deprecated stuff, change the gl3 import to this: import derelict.opengl3.gl; And call load/reload on the DerelictGL instance rather than DerelictGL3. All of the modern stuff will still be available. --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com
Sep 24 2014
parent reply "csmith" <csmith.ku2013 gmail.com> writes:
On Wednesday, 24 September 2014 at 11:07:56 UTC, Mike Parker
wrote:
 You're using deprecated OpenGL calls. The gl3 module only 
 declares and loads modern OpenGL. If you really want to use the 
 deprecated stuff, change the gl3 import to this:

 import derelict.opengl3.gl;

 And call load/reload on the DerelictGL instance rather than 
 DerelictGL3. All of the modern stuff will still be available.
Thanks for this. Was using GLFW's example trying to troubleshoot it. Wasn't really considering them using the outdated functions. I guess I'll look for a different tutorial elsewhere. Also, thanks for making it in the first place!
Sep 24 2014
next sibling parent reply "Nicolas F." <ddev fratti.ch> writes:
Whoops, I just saw that my earlier answer was totally inaccurate.
I was on my phone at the time, so didn't look at the code in
detail.

On Wednesday, 24 September 2014 at 13:59:41 UTC, csmith wrote:
 On Wednesday, 24 September 2014 at 11:07:56 UTC, Mike Parker
 wrote:
 You're using deprecated OpenGL calls. The gl3 module only 
 declares and loads modern OpenGL. If you really want to use 
 the deprecated stuff, change the gl3 import to this:

 import derelict.opengl3.gl;

 And call load/reload on the DerelictGL instance rather than 
 DerelictGL3. All of the modern stuff will still be available.
Thanks for this. Was using GLFW's example trying to troubleshoot it. Wasn't really considering them using the outdated functions. I guess I'll look for a different tutorial elsewhere. Also, thanks for making it in the first place!
topic. If you've been reading NeHe, drop it. NeHe is severely out of date and anyone still recommending it probably don't know what they're talking about. Here's some links: http://www.arcsynthesis.org/gltut/ https://github.com/progschj/OpenGL-Examples https://github.com/g-truc/ogl-samples Note that modern OpenGL is a bit more involved to get something on the screen. You'll be writing a lot more boilerplate in the beginning, but a lot of the modern features are definitely worth it.
Sep 24 2014
parent reply "csmith" <csmith.ku2013 gmail.com> writes:
 Whoops, I just saw that my earlier answer was totally 
 inaccurate.
 I was on my phone at the time, so didn't look at the code in
 detail.
No big deal, figured you just missed it / auto response to this kinda question. I did my best to google this question, but wasn't really sure where to begin.

 topic. If you've been reading NeHe, drop it. NeHe is severely 
 out
 of date and anyone still recommending it probably don't know 
 what
 they're talking about.

 Here's some links:
 http://www.arcsynthesis.org/gltut/
 https://github.com/progschj/OpenGL-Examples
 https://github.com/g-truc/ogl-samples
Exactly the kinda thing I was looking for. Thanks for the heads up about NeHe.
 Note that modern OpenGL is a bit more involved to get something
 on the screen. You'll be writing a lot more boilerplate in the
 beginning, but a lot of the modern features are definitely worth
 it.
I came from web development, you're meaning to tell me there's coding outside of writing boilerplate? Jokes aside, figured if I took the time to learn a modern language, I'd be consistent with adding in newer technologies :)
Sep 24 2014
parent "Nicolas F." <ddev fratti.ch> writes:
On Wednesday, 24 September 2014 at 16:36:29 UTC, csmith wrote:

 I came from web development, you're meaning to tell me there's 
 coding outside of writing boilerplate? Jokes aside, figured if 
 I took the time to learn a modern language, I'd be consistent 
 with adding in newer technologies :)
In that case, here's some two things on the way that may not be all that intuitive for a web developer when it comes to dealing with OpenGL, as they are quirks stemming mostly from how C works: 1. When you need to pass an array of some sort to an OpenGL function, remember to use foo.ptr, not &foo. foo.ptr will get you a pointer to an array that the rest of the world, not just D, understands. 2. The OpenGL spec mandates that empty error logs for shader compilation are to report length 0, but if you ask on an nvidia machine about the length of its empty error log, it will reply with length 1. This is because nvidia just send the length of the string in all cases, which for empty C strings is 1 due to the null-byte. I hope this helps you along, good luck!
Sep 24 2014
prev sibling parent "MrSmith" <mrsmith33 yandex.ru> writes:
On Wednesday, 24 September 2014 at 13:59:41 UTC, csmith wrote:
 On Wednesday, 24 September 2014 at 11:07:56 UTC, Mike Parker
 wrote:
 You're using deprecated OpenGL calls. The gl3 module only 
 declares and loads modern OpenGL. If you really want to use 
 the deprecated stuff, change the gl3 import to this:

 import derelict.opengl3.gl;

 And call load/reload on the DerelictGL instance rather than 
 DerelictGL3. All of the modern stuff will still be available.
Thanks for this. Was using GLFW's example trying to troubleshoot it. Wasn't really considering them using the outdated functions. I guess I'll look for a different tutorial elsewhere. Also, thanks for making it in the first place!
We have opengl tutorials in D https://github.com/d-gamedev-team/opengl-tutorials
Sep 25 2014