GLFW und codeblocks
Ich bin mit einigen Schwierigkeiten mit codeblocks 10.05 Anerkennung der GLFW-Bibliotheken auf meinem Rechner. Wenn ich ein leeres Projekt anlegen und kopieren Sie diesen code, der sich aus dieser GLFW tutorial >> http://content.gpwiki.org/index.php/GLFW:Tutorials:Basics
#include <stdlib.h>
#include <GL/glfw.h>
void Init(void);
void Shut_Down(int return_code);
void Main_Loop(void);
void Draw_Square(float red, float green, float blue);
void Draw(void);
float rotate_y = 0,
rotate_z = 0;
const float rotations_per_tick = .2;
int main(void)
{
Init();
Main_Loop();
Shut_Down(0);
}
void Init(void)
{
const int window_width = 800,
window_height = 600;
if (glfwInit() != GL_TRUE)
Shut_Down(1);
//800 x 600, 16 bit color, no depth, alpha or stencil buffers, windowed
if (glfwOpenWindow(window_width, window_height, 5, 6, 5,
0, 0, 0, GLFW_WINDOW) != GL_TRUE)
Shut_Down(1);
glfwSetWindowTitle("The GLFW Window");
//set the projection matrix to a normal frustum with a max depth of 50
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
float aspect_ratio = ((float)window_height) /window_width;
glFrustum(.5, -.5, -.5 * aspect_ratio, .5 * aspect_ratio, 1, 50);
glMatrixMode(GL_MODELVIEW);
}
void Shut_Down(int return_code)
{
glfwTerminate();
exit(return_code);
}
void Main_Loop(void)
{
//the time of the previous frame
double old_time = glfwGetTime();
//this just loops as long as the program runs
while(1)
{
//calculate time elapsed, and the amount by which stuff rotates
double current_time = glfwGetTime(),
delta_rotate = (current_time - old_time) * rotations_per_tick * 360;
old_time = current_time;
//escape to quit, arrow keys to rotate view
if (glfwGetKey(GLFW_KEY_ESC) == GLFW_PRESS)
break;
if (glfwGetKey(GLFW_KEY_LEFT) == GLFW_PRESS)
rotate_y += delta_rotate;
if (glfwGetKey(GLFW_KEY_RIGHT) == GLFW_PRESS)
rotate_y -= delta_rotate;
//z axis always rotates
rotate_z += delta_rotate;
//clear the buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//draw the figure
Draw();
//swap back and front buffers
glfwSwapBuffers();
}
}
void Draw_Square(float red, float green, float blue)
{
//Draws a square with a gradient color at coordinates 0, 10
glBegin(GL_QUADS);
{
glColor3f(red, green, blue);
glVertex2i(1, 11);
glColor3f(red * .8, green * .8, blue * .8);
glVertex2i(-1, 11);
glColor3f(red * .5, green * .5, blue * .5);
glVertex2i(-1, 9);
glColor3f(red * .8, green * .8, blue * .8);
glVertex2i(1, 9);
}
glEnd();
}
void Draw(void)
{
//reset view matrix
glLoadIdentity();
//move view back a bit
glTranslatef(0, 0, -30);
//apply the current rotation
glRotatef(rotate_y, 0, 1, 0);
glRotatef(rotate_z, 0, 0, 1);
//by repeatedly rotating the view matrix during drawing, the
//squares end up in a circle
int i = 0, squares = 15;
float red = 0, blue = 1;
for (; i < squares; ++i){
glRotatef(360.0/squares, 0, 0, 1);
//colors change for each square
red += 1.0/12;
blue -= 1.0/12;
Draw_Square(red, .6, blue);
}
}
und kompilieren Sie es mit codeblocks es gibt mir diese Fehlermeldung:
/home/user/Graphics/Project_2/test.c|27|undefined reference to `glfwInit'|
/home/user/Graphics/Project_2/test.c|30|undefined reference to `glfwOpenWindow'|
......
.....
....
...
aber wenn ich erstellen Sie eine einfache *.c-Datei und kompilieren Sie es mit :
gcc myprog.c -o myprog -lglfw -lGL -lpthread
es funktioniert.. Wie kann ich machen codeblocks arbeiten mit GLFW??
Dank
Du musst angemeldet sein, um einen Kommentar abzugeben.
Befolgen Sie das folgende Verfahren.
und füge Sie in den Ordner "C:\Program Files\CodeBlocks\MinGW\lib"
innen "C:\Windows\System32" floder. Wenn Sie nicht mögen, zu halten, im system32, dann können Sie halten Sie es mit Ihrer Projekt-exe-Datei.
lib-mingw
undlib-mingw-w64
. Welche soll ich verwenden? (Windows 10 64-bit mit MinGW installiert von der web-installer (welche version auch immer das ist)).Stellen Sie sicher, dass Sie die richtige Art von glfw libs. ie x86-oder x64-für Ihren mingw-compiler. 8 Stunden Zeit mit der Suche für Sie undefined reference-Fehler ie linker Probleme zu glfw.
Befolgen Sie diese instrucions:
http://codeincodeblock.blogspot.com/2011/02/setup-glfw-project-in-codeblock.html
Ich hatte ähnliche Probleme früher mit dem Import von GLFW in codeblocks, und vor kurzem habe ich etwas gefunden, das funktioniert für mich.
Kann ich sehen, dass Sie bereits getan haben, die header-installation korrekt, aber ich werde auch, dass in dieser Reaktion, so dass Sie doppelt überprüfen, dass alles ist in tip-top Zustand.
Ich auch empfehlen, dass Sie den Beispielcode verwenden, in der 'Dokumentation' tab glfw.org. Es funktioniert wirklich gut für mich, so dass ich denke, es könnte für Sie als gut.
Da Sie mit GLFW, gehe ich davon aus, das Sie verwenden möchten OpenGL in Ihrer Anwendung, also werde ich die installation von OpenGL in das tutorial
A. Anlegen der relevanten Ordner
Das erste, was Sie tun müssen, ist richten Sie einen Speicherort für die Bibliothek-Dateien und header-Dateien auf Ihrem system. Sie können entweder erstellt diese Ordner in einem bestimmten Verzeichnis auf Ihrem Laufwerk zu erhalten, oder Sie können erstellen Sie die folgenden Ordner in Ihrem " code::blocks-Projekt.
In meinem Fall erstellte ich ein 'lib' und 'Kopf' - Ordner in meinem code::blocks-Projekt-Ordner.
B. Downloaden & Installieren von notwendigen Medien
GLFW:
GLEW (OpenGL):
An dieser Stelle, Ihre "Kopf" - Ordner enthalten sollte 'GLFW' und 'GL' Ordner, und dein 'lib' Ordner enthalten sollte 'glew32', 'glew32s', und alle von der Bibliothek Dateien von GLFW für Ihren compiler.
C. Konfigurieren Sie Ihren code::blocks-Projekt
D. Erstellen und Ausführen von code :)! Hoffe, das hilft!