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

Username:   Password: 
 RegisterRegister   
 Texturing With OpenGL
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Homer_simpson




PostPosted: Tue Jun 03, 2003 9:10 pm   Post subject: Texturing With OpenGL

ok here's a code created by Dev C++ and it creates one simple 3d surface...
Does anybody know how to texture a surface in OpenGL?!?!?!??!
code:
/**************************
 * Includes
 *
 **************************/

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


/**************************
 * Function Declarations
 *
 **************************/

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);


/**************************
 * WinMain
 *
 **************************/

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,
      100, 100, 1000, 700,
      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
        {
            /* OpenGL animation code goes here */

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

            glPushMatrix ();
            glRotatef (theta, 0.0f, 0.0f, 1.0f);
            glRotatef (theta*2, 0.0f, 1.0f, 0.0f);
          glColor3f(0.5f,0.5f,0.5f);
            glBegin (GL_QUADS);
                glVertex3f(-0.5f, -0.5f,  0.0f);
                glVertex3f( 0.5f, -0.5f,  0.0f);
                glVertex3f( 0.5f,  0.5f,  0.0f);
            glVertex3f(-0.5f,  0.5f,  0.0f);
            glEnd ();
            glPopMatrix ();

            SwapBuffers (hDC);

            theta += 1.f;
        }
    }

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

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

    return msg.wParam;
}


/********************
 * Window Procedure
 *
 ********************/

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);
    }
}


/*******************
 * Enable OpenGL
 *
 *******************/

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 );

}


/******************
 * Disable OpenGL
 *
 ******************/

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




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

there r some good tuts by nehe
the difficult part , i find , is getting a good image loader
Homer_simpson




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

oh i found out what the problem was Very Happy... for some reason i'm missing
glaux.h file will u send it to me catalyst (it's located at includes\gl\)...
thx
Catalyst




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

im missing the glaux.dll file
Homer_simpson




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

but what about the .h file?! missing also?!
Catalyst




PostPosted: Tue Jun 03, 2003 11:19 pm   Post subject: (No subject)

if u dont have the h file, you prob wont have the dll
Homer_simpson




PostPosted: Wed Jun 04, 2003 7:57 am   Post subject: (No subject)

i've searched the net... =/ i cant find it Crying or Very sad Crying or Very sad
Homer_simpson




PostPosted: Wed Jun 04, 2003 4:09 pm   Post subject: (No subject)

guess what i found...
glaux.dll damn thing... (took me a while to find it but here it is...)



glaux.zip
 Description:
Opengl file used for texturing...

Download
 Filename:  glaux.zip
 Filesize:  119.59 KB
 Downloaded:  1534 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Kingnoz




PostPosted: Thu Jun 05, 2003 10:32 am   Post subject: (No subject)

here is the glaux.h


GLAUX.H
 Description:

Download
 Filename:  GLAUX.H
 Filesize:  11.74 KB
 Downloaded:  2555 Time(s)

Homer_simpson




PostPosted: Fri Jun 06, 2003 12:51 pm   Post subject: (No subject)

when i use texturing the textures i use always have to be 256x256... can u explain to me why that is..? and how can i change it...?
Catalyst




PostPosted: Fri Jun 06, 2003 2:27 pm   Post subject: (No subject)

the dont have to be 256x256
they have to be a power of 2 (16,32,64,128,256,etc)
im not sure why tho
rizzix




PostPosted: Thu Jun 26, 2003 9:46 am   Post subject: (No subject)

hmm...
it's probably because, u use bitmap textures or something..
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 12 Posts ]
Jump to:   


Style:  
Search: