Results 1 to 5 of 5

Thread: ...6 pages of code? for a triange?

  1. #1
    Guest

    ...6 pages of code? for a triange?

    Would someone please just reassure me that this tutorial that Downloaded that uses up 6 pages of code just to draw a white triangle onto the screen is only this big because its explanatory... Oh wait..its nothing but code, and most of this stuff doesn't make much sense. . . SO are you guys suggesting that I know Windows Proggin (i think thats called like "win32 API" or something) in order to prog in oGL?

  2. #2
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,595

    Re: ...6 pages of code? for a triange?

    Hi !

    In OpenGL:
    glBegin( GL_TRIANGLES);
    glVertex3d( x1, y1, z1);
    glVertex3d( x1, y1, z1);
    glVertex3d( x1, y1, z1);
    glEnd();

    If you an old example of Direct3D code, then it might be true, drawing I triangle in the first versions of Direct3D was something like one or two pages of code...

    Mikael

  3. #3
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,595

    Re: ...6 pages of code? for a triange?

    Ooops, sorry, it should of course have been x1,y1,z1 x2,y2,z2 and so on.

    You do not need to now any Win32 to do OpenGL applications, if you use GLUT or SDL or other platform independent solutions.

    Mikael

  4. #4
    Guest

    Re: ...6 pages of code? for a triange?

    If you wanna avoid the windows code all together you can use glut. You can pick it up at http://www.xmission.com/~nate/glut.html
    I'll include a what I think is a minial opengl code that will draw a quad. Hope noone minds me pasteing it here. There are probable better ways to do what I'm doing but I'm learning openGL too =)

    #include <GL/glut.h> //includes all the OpenGL headers and also the windows.h header if needed

    #define WINDOW_NAME "OpenGL Application" //The name that will appear in the title bar

    GLfloat CLEAR_COLOR[4] ={0.0f, 0.0f, 0.0f, 0.0f};

    /*
    Draws a simple quad at -2 on the z axis
    */
    void DrawQuad(void)
    {

    //sets the color of the quad, in this case purely red
    //glColor3f(red, blue, green);
    glColor3f(1.0f, 0.0f, 0.0f);
    glBegin(GL_QUADS); //begin drawing
    //glVertex3f(x-axis, y-axis, z-axis);
    glVertex3f(-1.0f, 1.0f,-4.0f);
    glVertex3f(-1.0f, -1.0f,-4.0f);
    glVertex3f(1.0f, -1.0f,-4.0f);
    glVertex3f(1.0f, 1.0f,-4.0f);
    glEnd(); //end drawing the quad
    }


    /*
    DrawGL clears the buffer and then does the drawing and finall the displaying
    */

    void DrawGL(void)
    {
    glClear(GL_COLOR_BUFFER_BIT); //Clear the background
    glPushMatrix(); //save the current matrix
    glLoadIdentity(); //load the identity matrix
    DrawQuad(); //draw the quad
    glPopMatrix(); //restores the matrix
    glFlush();
    glutSwapBuffers();
    }

    /*
    Resize is called when the window is resized.
    Sets up the aspect ratio and viewing/modeling matrix
    */
    void Resize(GLsizei width, GLsizei height)
    {
    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f, (GLfloat)width/ (GLfloat)height, 0.1f, 1000.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    }

    /*
    Initialized Core opengl settings
    */
    bool InitGL(void)
    {
    glShadeModel(GL_SMOOTH); //use smooth shading
    //Sets the color of the background
    glClearColor(CLEAR_COLOR[0], CLEAR_COLOR[1], CLEAR_COLOR[2], CLEAR_COLOR[3] );
    return true;
    }

    /*
    Function to call when idle.
    */
    void Idle(void)
    {
    glutPostRedisplay();
    }


    int main(int argc, char** argv)
    {
    glutInit(&argc, argv);
    glutInitWindowSize(800, 600); //800x600 window size
    glutInitWindowPosition(0,0); //sets the windows initial windows position to the
    //upper left hand corner
    //The window will use RGB color, double buffer, and a alpha buffer
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_ALPHA);
    glutCreateWindow(WINDOW_NAME); //The window's title
    InitGL();
    glutDisplayFunc(DrawGL); //The main display function, where all the drawing happens
    glutReshapeFunc(Resize); //Function to call when user resizes the window
    glutIdleFunc(Idle); //Function that runs with idle
    glutMainLoop(); //enters the opengl main loop
    return 1;
    }

  5. #5
    Member Newbie
    Join Date
    Dec 2000
    Location
    Donetsk, Ukraine
    Posts
    48

    Re: ...6 pages of code? for a triange?

    What do you mean programming on OpenGL? In most cases graphics programming requires some kind of input by user (usually using mouse or keyboard). If you wanna do something like it on windows platform, you, maybe, should know WinAPI a little. Of course, you may use object wrappers like MFC or VCL(on Delphi and BCB). But its not much easier.

Similar Threads

  1. Can't access API pages
    By gdewan in forum OpenGL: General
    Replies: 2
    Last Post: 08-28-2012, 10:16 AM
  2. SDK API ref pages down much of the time
    By Dark Photon in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 05-15-2012, 06:20 AM
  3. Anybody with 2.1 man pages?
    By outofsync in forum OpenGL: Linux
    Replies: 1
    Last Post: 09-28-2009, 06:55 AM
  4. Man pages
    By in forum OpenGL: Linux
    Replies: 1
    Last Post: 11-20-2001, 03:32 AM
  5. reference pages
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-28-2000, 12:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean