में परिवर्तित नहीं कर सकता है। मैं Win32 संदर्भ में कोड ब्लॉक (minGW) के साथ ग्लेव और ओपनग्ल 3.2 को काम करने की कोशिश कर रहा हूं। मुझे एक अच्छा छोटा ट्यूटोरियल here'एलपीसीडब्लूआरटी {उर्फ कॉन्स wchar_t *}' को 'एलपीसीस्ट्रेट {उर्फ कॉन्स char *}
जैसा कि मैं कोडबॉक्स में ग्लेव को संकलित करना संभवतः काम करने की कोशिश कर रहा था, वास्तव में संभव था कि मैं यह देखने के लिए ट्यूटोरियल करने से पहले स्रोत को आजमा देना चाहता था कि यह काम करेगा या नहीं।
कोड को ट्वीक करने के बाद मैंने संकलन करने की कोशिश की और कई त्रुटियां मिलीं जिन्हें मैंने पहले कभी नहीं देखा है। वे इस प्रकार हैं
|In function 'bool createWindow(LPCWSTR, int, int)':|
|73|error: cannot convert 'LPCWSTR {aka const wchar_t*}' to 'LPCSTR {aka const char*}' in assignment|
|80|error: cannot convert 'LPCWSTR {aka const wchar_t*}' to 'LPCSTR {aka const char*}' for argument '2' to 'HWND__* CreateWindowExA(DWORD, LPCSTR, LPCSTR, DWORD, int, int, int, int, HWND, HMENU, HINSTANCE, LPVOID)'|
|In function 'int WinMain(HINSTANCE, HINSTANCE, LPSTR, int)':|
|105|warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]|
|110|error: '_TRUNCATE' was not declared in this scope|
|110|error: 'mbstowcs_s' was not declared in this scope|
मेरे कोड
include <iostream>
#include <Windows.h>
#ifndef GLEW_STATIC
#define GLEW_STATIC
#endif //GLEW_STATIC
#include <GL/glew.h>
#include <GL/wglew.h>
//using namespace std;
//
//int main()
//{
// cout << "Hello world!" << endl;
// return 0;
//}
#include "opengl_3.h"
OpenGLContext openglContext; // Our OpenGL Context class
bool running = true; // Whether or not the application is currently running
HINSTANCE hInstance; // The HINSTANCE of this application
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Standard window callback
/**
WndProc is a standard method used in Win32 programming for handling Window messages. Here we
handle our window resizing and tell our OpenGLContext the new window size.
*/
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
switch (message) {
case WM_SIZE: // If our window is resizing
{
openglContext.reshapeWindow(LOWORD(lParam), HIWORD(lParam)); // Send the new window size to our OpenGLContext
break;
}
case WM_DESTROY:
{
PostQuitMessage(0);
break;
}
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
/**
createWindow is going to create our window using Windows API calls. It is then going to
create our OpenGL context on the window and then show our window, making it visible.
*/
bool createWindow(LPCWSTR title, int width, int height) {
WNDCLASS windowClass;
HWND hWnd;
DWORD dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
hInstance = GetModuleHandle(NULL);
windowClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
windowClass.lpfnWndProc = (WNDPROC) WndProc;
windowClass.cbClsExtra = 0;
windowClass.cbWndExtra = 0;
windowClass.hInstance = hInstance;
windowClass.hIcon = LoadIcon(NULL, IDI_WINLOGO);
windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
windowClass.hbrBackground = NULL;
windowClass.lpszMenuName = NULL;
windowClass.lpszClassName = title;
if (!RegisterClass(&windowClass)) {
return false;
}
hWnd = CreateWindowEx(dwExStyle, title, title, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, width, height, NULL, NULL, hInstance, NULL);
openglContext.create30Context(hWnd); // Create our OpenGL context on the given window we just created
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
return true;
}
/**
WinMain is the main entry point for Windows based applications as opposed to 'main' for console
applications. Here we will make the calls to create our window, setup our scene and then
perform our 'infinite' loop which processes messages and renders.
*/
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
MSG msg;
/**
The following 6 lines of code do conversion between char arrays and LPCWSTR variables
which are used in the Windows API.
*/
char *orig = "OpenGL 3 Project"; // Our windows title
size_t origsize = strlen(orig) + 1;
const size_t newsize = 100;
size_t convertedChars = 0;
wchar_t wcstring[newsize];
mbstowcs_s(&convertedChars, wcstring, origsize, orig, _TRUNCATE);
createWindow(wcstring, 500, 500); // Create our OpenGL window
openglContext.setupScene(); // Setup our OpenGL scene
/**
This is our main loop, it continues for as long as running is true
*/
while (running)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { // If we have a message to process, process it
if (msg.message == WM_QUIT) {
running = false; // Set running to false if we have a message to quit
}
else {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else { // If we don't have a message to process
openglContext.renderScene(); // Render our scene (which also handles swapping of buffers)
}
}
return (int) msg.wParam;
}
(पाठ की दीवार के बारे में क्षमा करें) है वहाँ भी अन्य फ़ाइलों रहे हैं, लेकिन सभी त्रुटियों को यहां से बनने लगते हैं। यदि आवश्यक हो तो बीमार पोस्ट करें।
मैंने वास्तव में इस तरह की कोई भी त्रुटि नहीं देखी है, इसलिए मैंने कुछ googling किया और पता चला कि त्रुटि बहु बाइट (VS2010 में एक सेटिंग) पर सेट नहीं किया जा रहा है। मैंने कुछ लोगों को देखा और कोडब्लॉक्स में ऐसी कोई सेटिंग नहीं मिली। क्या यह कोड केवल वीएस में प्रयोग योग्य है या क्या मुझे कुछ याद आया है? मुझे चिंता है कि मेरे साथ इस संबंध में कुछ समस्याएं हो सकती हैं क्योंकि मुझे अतीत में बहुत सारे मुद्दे हैं। किसी भी सहायता की सराहना की जाएगी।
हे मदद के लिए धन्यवाद, ऐसा लगता है कि यह चाल चल रही है। मुझे एक और त्रुटि मिल रही है हालांकि "mbstowcs_s (और परिवर्तित चार्ज, wcstring, origsize, orig, _TRUNCATE);" क्या यह एक विंडोज़ समारोह के लिए एक कॉल होगा? यह कहता है कि यह अव्यवस्थित है। –
@IPhantasmI: जहां तक मुझे पता है, 'mbstowcs_s' वीसी ++ - विशिष्ट है। MinGW के साथ, बस इसके बजाय ['std :: mbstowcs'] (http://en.cppreference.com/w/cpp/string/multibyte/mbstowcs) का उपयोग करें। – ildjarn
क्या इनपुट चर बदलने की आवश्यकता होगी। मैं अनुमान लगा रहा हूं कि मुझे आपके द्वारा सुझाए गए फ़ंक्शन कॉल को बस स्थानांतरित करने से बहुत सारी त्रुटियां मिल रही हैं। मुझे विंडोज एपीआई के साथ ज्यादा अनुभव नहीं है इसलिए मुझे वास्तव में यह सुनिश्चित नहीं है कि वह चर रूपांतरण कैसे पूरा कर रहा है। –