opengl cstring doesnt name a type



  • Erstmal die codes:

    main.cpp:

    #include <main.h>
    #include <glew.h> // http://glew.sourceforge.net/
    #include <wglew.h>
    #include <string.h>

    // ----------------------------------------------------------------------------------------------------------------------------

    COpenGLRenderer::COpenGLRenderer()
    {
    }

    COpenGLRenderer::~COpenGLRenderer()
    {
    }

    bool COpenGLRenderer::Init()
    {
    GLfloat LightModelAmbient[] = {0.0f, 0.0f, 0.0f, 1.0f};
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, LightModelAmbient);

    GLfloat LightAmbient[] = {0.25f, 0.25f, 0.25f, 1.0f};
    glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);

    GLfloat LightDiffuse[] = {0.75f, 0.75f, 0.75f, 1.0f};
    glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse);

    GLfloat MaterialAmbient[] = {1.0f, 1.0f, 1.0f, 1.0f};
    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, MaterialAmbient);

    GLfloat MaterialDiffuse[] = {1.0f, 1.0f, 1.0f, 1.0f};
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialDiffuse);

    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHTING);
    glEnable(GL_COLOR_MATERIAL);

    return true;
    }

    void COpenGLRenderer::Render(float FrameTime)
    {
    static float LightPosition[] = {0.0f, 0.0f, 2.5f, 1.0f}, a = 0.0f;

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0.0f, 0.0f, 2.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);

    glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);

    glRotatef(a, 0.0f, 1.0f, 0.0f);
    glRotatef(a, 1.0f, 0.0f, 0.0f);

    glColor3f(1.0f, 1.0f, 1.0f);

    glBegin(GL_QUADS);

    glNormal3f( 0.0f, 0.0f, 1.0f);
    glVertex3f(-0.5f, -0.5f, 0.5f);
    glVertex3f( 0.5f, -0.5f, 0.5f);
    glVertex3f( 0.5f, 0.5f, 0.5f);
    glVertex3f(-0.5f, 0.5f, 0.5f);

    glNormal3f( 0.0f, 0.0f, -1.0f);
    glVertex3f( 0.5f, -0.5f, -0.5f);
    glVertex3f(-0.5f, -0.5f, -0.5f);
    glVertex3f(-0.5f, 0.5f, -0.5f);
    glVertex3f( 0.5f, 0.5f, -0.5f);

    glNormal3f( 1.0f, 0.0f, 0.0f);
    glVertex3f( 0.5f, -0.5f, 0.5f);
    glVertex3f( 0.5f, -0.5f, -0.5f);
    glVertex3f( 0.5f, 0.5f, -0.5f);
    glVertex3f( 0.5f, 0.5f, 0.5f);

    glNormal3f(-1.0f, 0.0f, 0.0f);
    glVertex3f(-0.5f, -0.5f, -0.5f);
    glVertex3f(-0.5f, -0.5f, 0.5f);
    glVertex3f(-0.5f, 0.5f, 0.5f);
    glVertex3f(-0.5f, 0.5f, -0.5f);

    glNormal3f( 0.0f, 1.0f, 0.0f);
    glVertex3f(-0.5f, 0.5f, 0.5f);
    glVertex3f( 0.5f, 0.5f, 0.5f);
    glVertex3f( 0.5f, 0.5f, -0.5f);
    glVertex3f(-0.5f, 0.5f, -0.5f);

    glNormal3f( 0.0f, -1.0f, 0.0f);
    glVertex3f(-0.5f, -0.5f, -0.5f);
    glVertex3f( 0.5f, -0.5f, -0.5f);
    glVertex3f( 0.5f, -0.5f, 0.5f);
    glVertex3f(-0.5f, -0.5f, 0.5f);

    glEnd();

    a += 22.5f * FrameTime;
    }

    void COpenGLRenderer::Resize(int Width, int Height)
    {
    this->Width = Width;
    this->Height = Height;

    glViewport(0, 0, Width, Height);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f, (float)Width / (Height > 0 ? (float)Height : 1.0f), 0.125f, 512.0f);
    }

    void COpenGLRenderer::Destroy()
    {
    }

    // ----------------------------------------------------------------------------------------------------------------------------

    COpenGLRenderer OpenGLRenderer;

    // ----------------------------------------------------------------------------------------------------------------------------

    CString ErrorLog;

    // ----------------------------------------------------------------------------------------------------------------------------

    COpenGLView::COpenGLView()
    {
    }

    COpenGLView::~COpenGLView()
    {
    }

    bool COpenGLView::Init(HINSTANCE hInstance, char *Title, int Width, int Height)
    {
    this->Title = Title;
    this->Width = Width;
    this->Height = Height;

    WNDCLASSEX WndClassEx;

    memset(&WndClassEx, 0, sizeof(WNDCLASSEX));

    WndClassEx.cbSize = sizeof(WNDCLASSEX);
    WndClassEx.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
    WndClassEx.lpfnWndProc = WndProc;
    WndClassEx.hInstance = hInstance;
    WndClassEx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    WndClassEx.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    WndClassEx.hCursor = LoadCursor(NULL, IDC_ARROW);
    WndClassEx.lpszClassName = "Win32OpenGLWindow";

    if(RegisterClassEx(&WndClassEx) == 0)
    {
    ErrorLog.Set("RegisterClassEx failed!");
    return false;
    }

    DWORD Style = WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;

    hWnd = CreateWindowEx(WS_EX_APPWINDOW, WndClassEx.lpszClassName, Title, Style, 0, 0, Width, Height, NULL, NULL, hInstance, NULL);

    if(hWnd == NULL)
    {
    ErrorLog.Set("CreateWindowEx failed!");
    return false;
    }

    HDC hDC = GetDC(hWnd);

    if(hDC == NULL)
    {
    ErrorLog.Set("GetDC failed!");
    return false;
    }

    PIXELFORMATDESCRIPTOR pfd;

    memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));

    pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
    pfd.nVersion = 1;
    pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
    pfd.iPixelType = PFD_TYPE_RGBA;
    pfd.cColorBits = 32;
    pfd.cDepthBits = 24;
    pfd.iLayerType = PFD_MAIN_PLANE;

    int PixelFormat = ChoosePixelFormat(hDC, &pfd);

    if(PixelFormat == 0)
    {
    ErrorLog.Set("ChoosePixelFormat failed!");
    return false;
    }

    if(SetPixelFormat(hDC, PixelFormat, &pfd) == FALSE)
    {
    ErrorLog.Set("SetPixelFormat failed!");
    return false;
    }

    hGLRC = wglCreateContext(hDC);

    if(hGLRC == NULL)
    {
    ErrorLog.Set("wglCreateContext failed!");
    return false;
    }

    if(wglMakeCurrent(hDC, hGLRC) == FALSE)
    {
    ErrorLog.Set("wglMakeCurrent failed!");
    return false;
    }

    if(glewInit() != GLEW_OK)
    {
    ErrorLog.Set("glewInit failed!");
    return false;
    }

    if(WGLEW_EXT_swap_control)
    {
    wglSwapIntervalEXT(0);
    }

    return OpenGLRenderer.Init();
    }

    void COpenGLView::Show(bool Maximized)
    {
    RECT dRect, wRect, cRect;

    GetWindowRect(GetDesktopWindow(), &dRect);
    GetWindowRect(hWnd, &wRect);
    GetClientRect(hWnd, &cRect);

    wRect.right += Width - cRect.right;
    wRect.bottom += Height - cRect.bottom;
    wRect.right -= wRect.left;
    wRect.bottom -= wRect.top;
    wRect.left = dRect.right / 2 - wRect.right / 2;
    wRect.top = dRect.bottom / 2 - wRect.bottom / 2;

    MoveWindow(hWnd, wRect.left, wRect.top, wRect.right, wRect.bottom, FALSE);

    ShowWindow(hWnd, Maximized ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL);
    }

    void COpenGLView::MessageLoop()
    {
    MSG Msg;

    while(GetMessage(&Msg, NULL, 0, 0) > 0)
    {
    TranslateMessage(&Msg);
    DispatchMessage(&Msg);
    }
    }

    void COpenGLView::Destroy()
    {
    OpenGLRenderer.Destroy();
    wglDeleteContext(hGLRC);
    DestroyWindow(hWnd);
    }

    void COpenGLView::OnPaint()
    {
    static DWORD LastFPSTime = GetTickCount(), LastFrameTime = LastFPSTime, FPS = 0;

    PAINTSTRUCT ps;

    HDC hDC = BeginPaint(hWnd, &ps);

    DWORD Time = GetTickCount();

    float FrameTime = (Time - LastFrameTime) * 0.001f;

    LastFrameTime = Time;

    if(Time - LastFPSTime > 1000)
    {
    CString Text = Title;

    Text.Append(" - %dx%d", Width, Height);
    Text.Append(", FPS: %d", FPS);
    Text.Append(" - %s", (char*)glGetString(GL_RENDERER));

    SetWindowText(hWnd, Text);

    LastFPSTime = Time;
    FPS = 0;
    }
    else
    {
    FPS++;
    }

    OpenGLRenderer.Render(FrameTime);

    SwapBuffers(hDC);

    EndPaint(hWnd, &ps);

    InvalidateRect(hWnd, NULL, FALSE);
    }

    void COpenGLView::OnSize(int Width, int Height)
    {
    this->Width = Width;
    this->Height = Height;

    OpenGLRenderer.Resize(Width, Height);
    }

    // ----------------------------------------------------------------------------------------------------------------------------

    COpenGLView OpenGLView;

    // ----------------------------------------------------------------------------------------------------------------------------

    LRESULT CALLBACK WndProc(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
    {
    switch(uiMsg)
    {
    case WM_CLOSE:
    PostQuitMessage(0);
    break;

    case WM_PAINT:
    OpenGLView.OnPaint();
    break;

    case WM_SIZE:
    OpenGLView.OnSize(LOWORD(lParam), HIWORD(lParam));
    break;

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

    return 0;
    }

    // ----------------------------------------------------------------------------------------------------------------------------

    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR sCmdLine, int iShow)
    {
    char *AppName = "Cube rendering, rotating and lighting";

    if(OpenGLView.Init(hInstance, AppName, 800, 600))
    {
    OpenGLView.Show();
    OpenGLView.MessageLoop();
    }
    else
    {
    MessageBox(NULL, ErrorLog, AppName, MB_OK | MB_ICONERROR);
    }

    OpenGLView.Destroy();

    return 0;
    }

    main.h:

    #include <string.h>

    #include <glew.h> // http://glew.sourceforge.net/
    #include <wglew.h>

    // ----------------------------------------------------------------------------------------------------------------------------

    #pragma comment(lib, "opengl32.lib")
    #pragma comment(lib, "glu32.lib")
    #pragma comment(lib, "glew32.lib")

    // ----------------------------------------------------------------------------------------------------------------------------

    extern CString ErrorLog;

    // ----------------------------------------------------------------------------------------------------------------------------

    class COpenGLRenderer
    {
    protected:
    int Width, Height;

    public:
    COpenGLRenderer();
    ~COpenGLRenderer();

    bool Init();
    void Render(float FrameTime);
    void Resize(int Width, int Height);
    void Destroy();
    };

    // ----------------------------------------------------------------------------------------------------------------------------

    class COpenGLView
    {
    protected:
    char *Title;
    int Width, Height;
    HWND hWnd;
    HGLRC hGLRC;

    public:
    COpenGLView();
    ~COpenGLView();

    bool Init(HINSTANCE hInstance, char *Title, int Width, int Height);
    void Show(bool Maximized = false);
    void MessageLoop();
    void Destroy();

    void OnPaint();
    void OnSize(int Width, int Height);
    };

    // ----------------------------------------------------------------------------------------------------------------------------

    LRESULT CALLBACK WndProc(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam);

    // ----------------------------------------------------------------------------------------------------------------------------

    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR sCmdLine, int iShow);

    string.h:

    #include<main.h>
    #include <glew.h> // http://glew.sourceforge.net/
    #include <wglew.h>

    #if !defined(__STRING_H_)
    #define __STRING_H_

    #include <stddef.h>
    #include <sys_types.h>

    #ifdef __cplusplus
    extern "C" {
    #endif /* __cplusplus */

    extern void *memccpy(void *, const void *, int, size_t);
    extern void *memchr(const void *, int, size_t);
    extern int memcmp(const void *, const void *, size_t);
    extern void *memcpy(void *, const void *, size_t);
    extern void *memmove(void *, const void *, size_t);
    extern void *memset(void *, int, size_t);
    extern char *strcat(char *, const char *);
    extern char *strchr(const char *, int);
    extern int strcmp(const char *, const char *);
    extern char *strcpy(char *, const char *);
    extern int strcasecmp(const char *, const char *);
    extern size_t strlen(const char *);
    extern char *strlwr(char *);
    extern char *strncat(char *, const char *, size_t);
    extern int strncmp(const char *, const char *, size_t);
    extern char *strncpy(char *, const char *, size_t) ;
    extern int strncasecmp(const char *, const char *, size_t);
    extern size_t strnlen(const char *, size_t);
    extern char *strrchr(const char *, int);
    extern char *strrev(char *);
    extern char *strstr(const char *, const char *);
    extern char *strupr(char *);
    extern int bcmp(const void *b1, const void *b2, size_t length);
    extern char *strsep(char **, const char *);
    extern void bcopy(const void *, void *, size_t);
    extern size_t strlcat(char *, const char *, size_t);
    extern void * memset(void *, int, size_t);
    extern void bzero(void *, size_t);
    extern size_t strlcpy(char *, const char *, size_t);
    extern char * strdup(const char *);
    extern void swab(const void *, void *, size_t);
    extern char * strtok_r(char *s, const char *delim, char *last);
    extern char * strtok(char *s, const char *delim);
    extern size_t strspn(const char *s1, const char *s2);
    extern size_t strcspn(const char *s1, const char *s2);
    extern char
    strpbrk(const char *s1, const char *s2);

    #ifdef __cplusplus
    }
    #endif /* __cplusplus */

    #endif /* _STRING_H_ */

    stddef.h:

    #include <main.h>
    #include <glew.h> // http://glew.sourceforge.net/
    #include <wglew.h>
    #include <string.h>

    #ifndef __STDDEF_H
    #define __STDDEF_H

    #if !defined( __DEFS_H )
    #include <_defs.h>
    #endif

    #ifndef NULL
    #include <_null.h>
    #endif

    #ifndef _PTRDIFF_T
    #define _PTRDIFF_T
    #if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
    typedef long ptrdiff_t;
    #else
    typedef int ptrdiff_t;
    #endif
    #endif

    #ifndef _SIZE_T
    #define _SIZE_T
    typedef unsigned size_t;
    #endif

    #define offsetof( s_name, m_name ) (size_t)&(((s_name *)0)->m_name)

    #ifndef _WCHAR_T
    #define _WCHAR_T
    typedef char wchar_t;
    #endif

    #endif /* __STDDEF_H */

    sys/types:
    #include <main.h>
    #include <glew.h> // http://glew.sourceforge.net/
    #include <wglew.h>
    #include <string.h>

    #ifndef _TYPES_H_
    #define _TYPES_H_
    #pragma GCC system_header
    #include <_mingw.h>

    #define __need_wchar_t
    #define __need_size_t
    #define __need_ptrdiff_t
    #ifndef RC_INVOKED
    #include <stddef.h>
    #endif /* Not RC_INVOKED */

    #ifndef RC_INVOKED

    #ifndef _TIME32_T_DEFINED
    typedef __int32 __time32_t;
    #define _TIME32_T_DEFINED
    #endif

    #ifndef _TIME64_T_DEFINED
    typedef __int64 __time64_t;
    #define _TIME64_T_DEFINED
    #endif

    #ifndef _TIME_T_DEFINED
    /* FIXME __STRICT_ANSI__ ! */

    #if defined(_USE_32BIT_TIME_T) && MSVCRT_VERSION >= 800
    typedef __time32_t time_t;
    #else

    typedef __time64_t time_t;
    #endif /* _USE_32BIT_TIME_T */

    #define _TIME_T_DEFINED
    #endif

    #ifndef _OFF_T_
    #define _OFF_T_
    typedef long _off_t;
    #ifndef __STRICT_ANSI__
    typedef _off_t off_t;
    #endif /* __STRICT_ANSI__ /
    #endif /
    Not _OFF_T_ */

    #ifndef _OFF64_T_
    #define _OFF64_T_
    typedef __int64 _off64_t;
    #ifndef __STRICT_ANSI__
    typedef __int64 off64_t;
    #endif /* __STRICT_ANSI__ /
    #endif /
    ndef _OFF64_T */

    #ifndef _DEV_T_
    #define _DEV_T_
    typedef unsigned int _dev_t;

    #ifndef _NO_OLDNAMES
    typedef _dev_t dev_t;
    #endif
    #endif /* Not _DEV_T_ */

    #ifndef _INO_T_
    #define _INO_T_
    typedef short _ino_t;

    #ifndef _NO_OLDNAMES
    typedef _ino_t ino_t;
    #endif
    #endif /* Not _INO_T_ */

    #ifndef _PID_T_
    #define _PID_T_
    typedef int _pid_t;

    #ifndef _NO_OLDNAMES
    typedef _pid_t pid_t;
    #endif
    #endif /* Not _PID_T_ */

    #ifndef _MODE_T_
    #define _MODE_T_
    typedef unsigned short _mode_t;

    #ifndef _NO_OLDNAMES
    typedef _mode_t mode_t;
    #endif
    #endif /* Not _MODE_T_ */

    #ifndef _SIGSET_T_
    #define _SIGSET_T_
    typedef int _sigset_t;

    #ifndef _NO_OLDNAMES
    typedef _sigset_t sigset_t;
    #endif
    #endif /* Not _SIGSET_T_ */

    #ifndef _SSIZE_T_
    #define _SSIZE_T_
    typedef int _ssize_t;

    #ifndef _NO_OLDNAMES
    typedef _ssize_t ssize_t;
    #endif
    #endif /* Not _SSIZE_T_ */

    #ifndef _FPOS64_T_
    #define _FPOS64_T_
    typedef long long fpos64_t;
    #endif

    #ifndef _OFF64_T_
    #define _OFF64_T_
    typedef long long off64_t;
    #endif

    #if !defined __NO_ISOCEXT
    typedef unsigned int useconds_t;
    #endif /* Not __NO_ISOCEXT */

    #endif /* Not RC_INVOKED */

    #endif /* Not _TYPES_H_ */

    das war es !

    der compiler meint in main.h

    cstring doesnt name a type.was da falsch.
    thanx fuer die antwort.

    😉 🙂 🙂 😮


Anmelden zum Antworten