Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Terrain Demo
Index -> Programming, C++ -> C++ Tutorials
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Catalyst




PostPosted: Mon Jun 02, 2003 11:10 pm   Post subject: Terrain Demo

I am really beginning to like opengl Very Happy
this a terrain demo i made
its a bit blocky since the file it uses is low res



TerrainDemo.zip
 Description:

Download
 Filename:  TerrainDemo.zip
 Filesize:  139.1 KB
 Downloaded:  626 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Tue Jun 03, 2003 10:20 am   Post subject: (No subject)

Catalyst with his openGL skillz 8) Nice
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
nate




PostPosted: Tue Jun 03, 2003 2:59 pm   Post subject: (No subject)

Catalyst awsome terrain demo, but what program do u use for openGL
Catalyst




PostPosted: Tue Jun 03, 2003 3:09 pm   Post subject: (No subject)

dev c++
Catalyst




PostPosted: Tue Jun 03, 2003 3:37 pm   Post subject: (No subject)

heres a better version (i like alpha blending Very Happy )

it runs smoother since i used display lists



TerrainDemo.zip
 Description:

Download
 Filename:  TerrainDemo.zip
 Filesize:  138.54 KB
 Downloaded:  596 Time(s)

Homer_simpson




PostPosted: Tue Jun 03, 2003 5:21 pm   Post subject: (No subject)

I cant exactly see what that is but what ever it is it looks super dooper cool... so here's 20 bits....
question : how much do i need to know about c++ to start working with OpenGL... right now i know all the basic stuff(looping,if statements,operators,vars...) and i know basics of classes and pointers... what else do i need to know to get started?!
Catalyst




PostPosted: Tue Jun 03, 2003 5:44 pm   Post subject: (No subject)

you dont need to know much to get started
the experience you have is enough
Homer_simpson




PostPosted: Tue Jun 03, 2003 5:50 pm   Post subject: (No subject)

sweet... do i get started by starting a new project > multimedia>opengl>ok? or do i start a blank project?!
Sponsor
Sponsor
Sponsor
sponsor
Catalyst




PostPosted: Tue Jun 03, 2003 6:29 pm   Post subject: (No subject)

thats the best route since it will lessen the linker issues that you could run into
be warned tho you cant use glut in that mode
Homer_simpson




PostPosted: Tue Jun 03, 2003 8:05 pm   Post subject: (No subject)

ok but yo... i used samples and tutorials on gamedev.net to create a GL scene but they are so comlicated there are about 50 functions into it...
can u give me the shortest code possible that would create a GL window and draw some object in it?!(will give u bits for it Wink )
Catalyst




PostPosted: Tue Jun 03, 2003 8:07 pm   Post subject: (No subject)

pulled right from dev c++

to understand the gl functions
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/opengl/glfunc01_4f03.asp

code:

#include <windows.h>
#include <gl/gl.h>


LRESULT CALLBACK WndProc (HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam);
void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC);
void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC);


int WINAPI WinMain (HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpCmdLine,
                    int iCmdShow)
{
    WNDCLASS wc;
    HWND hWnd;
    HDC hDC;
    HGLRC hRC;       
    MSG msg;
    BOOL bQuit = FALSE;
    float theta = 0.0f;

    /* register window class */
    wc.style = CS_OWNDC;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor (NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = "GLSample";
    RegisterClass (&wc);

    /* create main window */
    hWnd = CreateWindow (
      "GLSample", "OpenGL Sample",
      WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
      0, 0, 256, 256,
      NULL, NULL, hInstance, NULL);

    /* enable OpenGL for the window */
    EnableOpenGL (hWnd, &hDC, &hRC);

    /* program main loop */
    while (!bQuit)
    {
        /* check for messages */
        if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
        {
            /* handle or dispatch messages */
            if (msg.message == WM_QUIT)
            {
                bQuit = TRUE;
            }
            else
            {
                TranslateMessage (&msg);
                DispatchMessage (&msg);
            }
        }
        else
        {
            //////////////////////////////////////////
           /// This is all that matters for your purposes now

            glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
            glClear (GL_COLOR_BUFFER_BIT);

            glPushMatrix ();
            glRotatef (theta, 0.0f, 0.0f, 1.0f);
            glBegin (GL_TRIANGLES);
            glColor3f (1.0f, 0.0f, 0.0f);   glVertex2f (0.0f, 1.0f);
            glColor3f (0.0f, 1.0f, 0.0f);   glVertex2f (0.87f, -0.5f);
            glColor3f (0.0f, 0.0f, 1.0f);   glVertex2f (-0.87f, -0.5f);
            glEnd ();
            glPopMatrix ();

            SwapBuffers (hDC);

            theta += 1.0f;
            /////////////////////////////////////////////////////////////
        }
    }

    /* shutdown OpenGL */
    DisableOpenGL (hWnd, hDC, hRC);

    /* destroy the window explicitly */
    DestroyWindow (hWnd);

    return msg.wParam;
}


LRESULT CALLBACK WndProc (HWND hWnd, UINT message,
                          WPARAM wParam, LPARAM lParam)
{

    switch (message)
    {
    case WM_CREATE:
        return 0;
    case WM_CLOSE:
        PostQuitMessage (0);
        return 0;

    case WM_DESTROY:
        return 0;

    case WM_KEYDOWN:
        switch (wParam)
        {
        case VK_ESCAPE:
            PostQuitMessage(0);
            return 0;
        }
        return 0;

    default:
        return DefWindowProc (hWnd, message, wParam, lParam);
    }
}



void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC)
{
    PIXELFORMATDESCRIPTOR pfd;
    int iFormat;

    /* get the device context (DC) */
    *hDC = GetDC (hWnd);

    /* set the pixel format for the DC */
    ZeroMemory (&pfd, sizeof (pfd));
    pfd.nSize = sizeof (pfd);
    pfd.nVersion = 1;
    pfd.dwFlags = PFD_DRAW_TO_WINDOW |
      PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
    pfd.iPixelType = PFD_TYPE_RGBA;
    pfd.cColorBits = 24;
    pfd.cDepthBits = 16;
    pfd.iLayerType = PFD_MAIN_PLANE;
    iFormat = ChoosePixelFormat (*hDC, &pfd);
    SetPixelFormat (*hDC, iFormat, &pfd);

    /* create and enable the render context (RC) */
    *hRC = wglCreateContext( *hDC );
    wglMakeCurrent( *hDC, *hRC );

}


void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC)
{
    wglMakeCurrent (NULL, NULL);
    wglDeleteContext (hRC);
    ReleaseDC (hWnd, hDC);
}
Homer_simpson




PostPosted: Tue Jun 03, 2003 8:37 pm   Post subject: (No subject)

yes i already understand that...(i know how to create 3d objects ,Rotations translations...) but i dont understand some of the functions that's used
EnableOpenGL (hWnd, &hDC, &hRC);
could u explain hWnd, &hDC, &hRC variables to me...
Homer_simpson




PostPosted: Tue Jun 03, 2003 8:47 pm   Post subject: (No subject)

and also the numeric system
glColor3f (1.0f, 0.0f, 0.0f); glVertex2f (0.0f, 1.0f);
is 0.0f hexadecimal...?!
Catalyst




PostPosted: Tue Jun 03, 2003 9:15 pm   Post subject: (No subject)

all the hDc stuff is just making the window (there no real need to understand it at this point)

the coor system is like a cartesian grid:
code:

            |
            |
            |(0,0)
     -------------
            |
            |
            |


the f at the end just mean float (GLFloat i think), it doesnt need to be there
Display posts from previous:   
   Index -> Programming, C++ -> C++ Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 14 Posts ]
Jump to:   


Style:  
Search: