inherit
66746
0
Oct 7, 2012 14:05:38 GMT -8
«The Silver Lining»™
^ Me !!!!
1,338
December 2005
chrisrulez001
|
Post by «The Silver Lining»™ on Feb 11, 2011 6:17:49 GMT -8
Hey
When using OpenGL for primitives, i have made a square on the screen but its at the bottom left hand corner and i cant seem to get it anywhere other than that bottom left hand corner.
The size of the window is 500 x 500
Heres the code:
float first_x = -1.0f; float first_y = -1.0f; float first_z = 0.0f; float second_x = -0.9f; float second_y = -1.0f; float second_z = 0.0f; float third_x = -0.9f; float third_y = -0.9f; float third_z = 0.0f; float fourth_x = -1.0f; float fourth_y = -0.9f; float fourth_z = 0.0f;
glBegin(GL_QUADS); glVertex3f(first_x, first_y, first_z); glVertex3f(second_x, second_y, second_z); glVertex3f(third_x, third_y, third_z); glVertex3f(fourth_x, fourth_y, fourth_z); glEnd();
|
|
#00AF33
14306
0
1
Sept 8, 2023 8:54:17 GMT -8
Jordan
What is truth?
11,838
October 2003
jab2
|
Post by Jordan on Feb 11, 2011 12:33:53 GMT -8
I haven't spent any time working with openGL since I spend most of my time working on school projects, but if you can give me something that compiles I may be able to figure it out. Are you working with C++ and SDL?
|
|
inherit
66746
0
Oct 7, 2012 14:05:38 GMT -8
«The Silver Lining»™
^ Me !!!!
1,338
December 2005
chrisrulez001
|
Post by «The Silver Lining»™ on Feb 11, 2011 14:44:11 GMT -8
Hi, its not C++ and SDL, its GLUT.
Heres the code:
#include <GL/glut.h>
bool fullscreen = false; int width = 500; int height = 500; int pos1 = 10; int pos2 = 10; char* title = "OpenGL Window";
bool init() { return true; }
void display() { glClearColor(0.5f, 0.5f, 0.5f, 0.5f); glClear(GL_COLOR_BUFFER_BIT); float first_x = -1.0f; float first_y = -1.0f; float first_z = 0.0f;
float second_x = -0.9f; float second_y = -1.0f; float second_z = 0.0f;
float third_x = -0.9f; float third_y = -0.9f; float third_z = 0.0f;
float fourth_x = -1.0f; float fourth_y = -0.9f; float fourth_z = 0.0f;
glBegin(GL_QUADS); glVertex3f(first_x, first_y, first_z); glVertex3f(second_x, second_y, second_z); glVertex3f(third_x, third_y, third_z); glVertex3f(fourth_x, fourth_y, fourth_z); glEnd();
glFlush(); glutSwapBuffers(); }
void keyboard(unsigned char key, int x, int y) { if (key == 27) exit(1); }
void specialKeyboard(int key, int x, int y) { if (key == GLUT_KEY_F1) { fullscreen = !fullscreen;
if (fullscreen) glutFullScreen(); else { glutReshapeWindow(width, height); glutPositionWindow(pos1, pos2); } } }
int main(int argc, char *argv[]) { glutInit(&argc, argv);
glutInitWindowPosition(pos1, pos2); glutInitWindowSize(width, height);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); glutCreateWindow(title);
glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutSpecialFunc(specialKeyboard);
if (!init()) { return 1; }
glutMainLoop();
return 0; }
|
|
#00AF33
14306
0
1
Sept 8, 2023 8:54:17 GMT -8
Jordan
What is truth?
11,838
October 2003
jab2
|
Post by Jordan on Feb 11, 2011 18:34:34 GMT -8
I downloaded Glut and was able to resize and move the square fairly easily with a tutorial. You just have to know where each point is on the graph. Check out the middle of this page. By the way, you need to change: char* title = "OpenGL Window"; to char title[] = "OpenGL Window"; The former doesn't make any sense because you're assigning a pointer to a string literal. Instead, you need to declare a char array of an unknown size and let the compiler do the rest. #include <windows.h> #ifdef __APPLE__ #include <GLUT/glut.h> #else #include <GL/glut.h> #endif
#include <stdlib.h>
#include <GL/glut.h>
bool fullscreen = false; int width = 500; int height = 500; int pos1 = 10; int pos2 = 10; char title[] = "OpenGL Window";
bool init() { return true; }
void display() { glClearColor(0.5f, 0.5f, 0.5f, 0.5f); glClear(GL_COLOR_BUFFER_BIT);
float first_x = 0.4f; float first_y = -0.4f; float first_z = 0.0f;
float second_x = 0.4f; float second_y = 0.4f; float second_z = 0.0f;
float third_x = -0.4f; float third_y = 0.4f; float third_z = 0.0f;
float fourth_x = -0.4f; float fourth_y = -0.4f; float fourth_z = 0.1f;
glBegin(GL_QUADS); glVertex3f(first_x, first_y, first_z); glVertex3f(second_x, second_y, second_z); glVertex3f(third_x, third_y, third_z); glVertex3f(fourth_x, fourth_y, fourth_z); glEnd();
glFlush(); glutSwapBuffers(); }
void keyboard(unsigned char key, int x, int y) { if (key == 27) exit(1); }
void specialKeyboard(int key, int x, int y) { if (key == GLUT_KEY_F1) { fullscreen = !fullscreen;
if (fullscreen) glutFullScreen(); else { glutReshapeWindow(width, height); glutPositionWindow(pos1, pos2); } } }
int main(int argc, char *argv[]) { glutInit(&argc, argv);
glutInitWindowPosition(pos1, pos2); glutInitWindowSize(width, height);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutCreateWindow(title);
glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutSpecialFunc(specialKeyboard);
if (!init()) { return 1; }
glutMainLoop();
return 0; }
|
|
inherit
66746
0
Oct 7, 2012 14:05:38 GMT -8
«The Silver Lining»™
^ Me !!!!
1,338
December 2005
chrisrulez001
|
Post by «The Silver Lining»™ on Feb 12, 2011 16:53:36 GMT -8
Right, thanks for your help.
I'll need to read that tutorial fully.
|
|
inherit
92635
0
Jun 28, 2011 4:10:37 GMT -8
draline
1,918
November 2006
draline
|
Post by draline on Feb 12, 2011 16:59:45 GMT -8
also if your using OpenGL primitives it is best to use C++, and Python with them , if your going the free linux server route etc. I work with OpenGL graphics programs, SDL's , DLL's etc often for my game engine.
|
|
#00AF33
14306
0
1
Sept 8, 2023 8:54:17 GMT -8
Jordan
What is truth?
11,838
October 2003
jab2
|
Post by Jordan on Feb 12, 2011 17:47:12 GMT -8
also if your using OpenGL primitives it is best to use C++, and Python with them , if your going the free linux server route etc. I work with OpenGL graphics programs, SDL's , DLL's etc often for my game engine. He is using C++. It also doesn't matter which OS he uses since he's using C++ with GLUT which are cross-platform. I'm a little confused by "SDL's" since SDL is a cross-platform multimedia library which stands for Simple DirectMedia Layer so you're essentially saying you work with "Simple DirectMedia Layer's". But yes, you're going to be using some DLL's when working on a game unless you feel like writing everything from scratch.
|
|
inherit
92635
0
Jun 28, 2011 4:10:37 GMT -8
draline
1,918
November 2006
draline
|
Post by draline on Feb 12, 2011 18:06:44 GMT -8
Well Considering the time I actually have. Using the DLL's for the media effects etc. This is the best way to go.and Yes I know what SDL are. They help me with the models. I have been Using C++, Python, Some Lua , XML works great for simple data in an RPG Engine. I have been working with this for over 2 Years. I Found that programming in these languages are not too hard just a lot of reading.
|
|