User forums > Using Code::Blocks
is it possible to create a new project creation wizard for glfw3?
(1/1)
Vigor:
I found this by searching which looks like it might be exactly what I'm looking for https://forums.codeblocks.org/index.php/topic,20927.msg142969.html#msg142969
I downloaded it but I don't know what to do with the downloaded file.
If that isn't a solution, could I possibly update or create a new wizard on my own?
I wasn't sure if I should comment on that post or create my own.
Vigor:
I have been working on a way to answer my own question.
I took the glfw project created from the wizard and modified it to work with glfw3. That requires changing some function names, adding a keyboard callback function to replace the functionality that causes the program to exit. The resulting code is below.
I also needed to add glu.h and windows.h. Glu.h needs windows.h to function and the original glfw.h probably included them but glfw3.h does not. I make that assessment because the original glfw project used glu functions.
--- Code: ---#define GLFW_DLL
#include <windows.h>
#include <glfw3.h>
#include <gl/glu.h>
#include <iostream>
GLFWwindow* window = NULL;
static void Keyboard(GLFWwindow *window, int key, int scancode, int action, int mods)
{
if(key == 256)//ESC = 256
{
glfwTerminate();
exit(-1);
}
}
int main()
{
int width = 512, height = 512;
int frame = 0;
if(!glfwInit())
throw std::runtime_error("glfwInit failed");
window = glfwCreateWindow(width, height, "Rotating Triangles",NULL, NULL);
if(!window)
throw std::runtime_error("glfwOpenWindow failed.");
glfwMakeContextCurrent(window);
//defines the keyboard callback as the global function above
glfwSetKeyCallback(window, Keyboard);
while(!glfwWindowShouldClose(window))
{
frame++;
// cout << frame << endl;
glfwGetWindowSize(window, &width, &height );
// height = height > 0 ? height : 1;
glViewport( 0, 0, width, height );
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glClear( GL_COLOR_BUFFER_BIT );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 65.0f, (GLfloat)width/(GLfloat)height, 1.0f, 100.0f );
// Draw some rotating garbage
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
gluLookAt(0.0f, -10.0f, 0.0f,
0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f );
//glTranslatef( 1.0f, 1.0f, 0.0f );
glRotatef(frame, 0.25f, 1.0f, 0.75f);
glBegin( GL_TRIANGLES );
glColor3f(0.1f, 0.0f, 0.0f );
glVertex3f(0.0f, 3.0f, -4.0f);
glColor3f(0.0f, 1.0f, 0.0f );
glVertex3f(3.0f, -2.0f, -4.0f);
glColor3f(0.0f, 0.0f, 1.0f );
glVertex3f(-3.0f, -2.0f, -4.0f);
glEnd();
glBegin( GL_TRIANGLES );
glColor3f(0.0f, 0.1f, 0.0f );
glVertex3f(0.0f, 3.0f, -3.0f);
glColor3f(0.0f, 0.0f, 1.0f );
glVertex3f(3.0f, -2.0f, -2.0f);
glColor3f(1.0f, 0.0f, 0.0f );
glVertex3f(-3.0f, -2.0f, 2.0f);
glEnd();
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
--- End code ---
additionally, I needed to modify linker settings to add some files. Project->Build Options->Linker Settings. Then use the add button to add the files...
libopengl32.a
libglfw3.a
libglfw3dll.a
Disclaimer: The path to .h's or .a's might not be the same on your computer.
*EDIT*
1. changed the esc key to 256. I originally put it at 250. (should have worn my glasses) 2. Made escape call glfwTerminate() instead of using the "bool running" variable
3. replaced running in the while loop to !glfwWindowShouldClose(window) because using running prevented the close button from working
4. added exit(-1) after esc button call to glfwTerminate(), otherwise the console window doesn't shut down.
Navigation
[0] Message Index
Go to full version