answerstu

c++ - Using OpenGL in a regular window (Win32)

I want to use OpenGL in my WndProc but I'm not sure how. I also don't want GL to occupy the whole screen, just a portion of the screen. In the end I basically want to make a drawing win32 app but use OGL instead of GDI. so how can I tell GL to use my control (a panel) 's hdc for drawing?Thanks...Read more

c++ - HINSTANCE & HWND Corrupted when passed around functions

I have a funny error occurring at runtime where my HINSTANCE and HWND variables are getting corrupted. I have posted the debugging output below and the line of code where the runtime error occurs. *Note: even though the screen capture kindof shows the HWND isn't corrupted, it doesn't point to the right/valid window anymoreWhy is this problem occurring and how can I fix it? WindowTiler.exe!WindowLayoutComponent::init(const IEventArgs & evtArgs) Line 26 C++ [External Code] WindowTiler.exe!EventDelegate::operator()(const IEventArgs &...Read more

c++ - Generate a WM_NCHITTEST message

I am trying to allow the user to move/resize a CEF borderless window (created with the WS_POPUP flag).The mouse position is caught in the CEF browser (using Javascript) and a C++ callback is called. Then, I send a message from the C++ callback to the CEF browser process via IPC (the message can contain HTRIGHT for example).The last step is moving or resizing the browser.I would like to generate WM_NCHITTEST messages in order to allow window moving/resizing.I tried to do it that way:PostMessage(getBrowserHwnd(), WM_NCHITTEST, 0, MAKELPARAM(curso...Read more

c++ - writing to memory mapped file while it is memory-mapped

I have memory mapped a file on disk as follow: const wchar_t fileName[] = L"temp.txt"; HANDLE h = CreateFile(fileName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); HANDLE fileMap = CreateFileMapping(h, NULL, PAGE_READWRITE, 0x0, 1024, NULL); char *ptr = (char *)MapViewOfFile(fileMap, FILE_MAP_WRITE | FILE_MAP_READ, 0, 0, 1024)Is it possible to write to the same file by another process while it is memory mapped?FILE *fp = fopen("temp.txt", "w+"); if(NULL == fp) printf("Failed to open\n");Above code always pri...Read more

c++ - Partially transparent window OpenGL/Win32

I have read every existing question on this tricky (niche) subject, but I am stuck. I have a Win32 window with an OpenGL context. I want my window to be partially transparent.My result so far is that the entirety of the window is transparent. I want only the black area to be transparent, so that I can draw some 3D objects and they will look like they are coming of the window. First, in my window class, I have set hbrBackground to black. Windows::WindowClass windowClass;windowClass.cbSize = sizeof(Windows::WindowClass);windowClass.style = Window...Read more

c++ - OpenGL movement object and rotate in same axis

I are trying add an object(triangle) in OpenGL, it move using glTranslatef() and rotate with glRotatef(), it is ok!I add one matrix of the grid in background and want hold position of the object(triangle) in center and rotate only grid background, ok works!However, when "walking" the object(triangle) using keys(up and down) it not rotate in same axis of the grid background.it seems that it is distancing the rotate when move!Code example:#include <algorithm>#include <iostream>#include <stdlib.h>#include <cmath>#include &l...Read more

c++ - What are the methods that are called when we invoke UpdateWindows() in MSDN?

I have an application where I am passing a handle ID of a window and calling UpdateWindow() method on that.The Problem is for small applications like notepad it takes hardly some 100 ms to finish updating the window,where as for my application it takes 1 min to finish updating the window.Hence,I wanted to know what are the methods which are being called in the background ,so that I can identify where is the time lag for my application....Read more

c++ - Problems with perspective in Open_GL

Could someone please explain me what is wrong in my code? When I try to run it I get a black window, but if I don't set the perspective matrix as I do in the 31th line I get the right solid (a pyramid) drawn on the window. Here's the main of the code. In the vertex shader I just define model, view and projection as uniform 4x4 matrices and multiply them by the poistion of the vertex and pass the colors of the vertices to the fragment shader. I don't think the problem is in those files but if you need them I'll post them. #include <iostream&g...Read more

c++ - Can i use OpenGL features from qt without having any kind of widget?

I'm trying to compute something on gpu using openGL compute shaders.But i want to keep this program in terminal, so i don't want any kind of widgets. For now it looks like i won't be able to call initializeOpenGLFunctions() or any others ogl related functions without getting Segmentation fault.Header#include <QOpenGLShaderProgram>#include <QOpenGLFunctions_4_5_Core>class SolverGPU : public QObject, protected QOpenGLFunctions_4_5_Core{ Q_OBJECTpublic: SolverGPU();private: QOpenGLShaderProgram* program;};SrcS...Read more

OpenGL flickers and draws more line than it should C++

I am working on a triangulation application where I can click inside a frame triangle in a window to subdivide it in 3 triangles and so on. Therefore, everytime I add a point, I add two triangles to a structure defined as the class Triangle (see Triangle.h and .cpp). For each object triangle, I keep track of its ID, the indices of its 3 vertices and the indices of its 3 adjacent triangles where first vertex and first adjacent triangle are opposite.I then draw every points and every triangles with GL_POINTS and GL_LINE_LOOP. If I use glClear(GL_...Read more

What are the main differences between a Rust Iterator and C++ Iterator?

A typical example of a C++ iterator is a pointer, and can be used to point at an element in a C array like so:int array[] = {1, 2, 3, 4};int* begin = std::begin(array); //Starting iteratorint* end = std::end(array) //Ending iteratorfor(int* i = begin; i < end; i++){ std::cout << *i << ',';}//Prints 1, 2, 3, 4This is simple enough. The definition of an iterator from cplusplus.com is An iterator is any object that, pointing to some element in a range of elements (such as an array or a container), has the ability to iterate thr...Read more

c++ - Error while compiling cocos2d-x v3 IOS project,on integrating AdMob (IOS) framework

When i compile my cocos2d-x V3 project in Xcode, it runs fine but on including AdMob framework, it displays following linker error.I already have included "-ObjC" in "Other linker" section under Build Settings. Undefined symbols for architecture armv7: "_kCMTimeZero", referenced from: -[GADVideoPlayer setAudioMixVolume:] in GoogleMobileAds(GADVideoPlayer.o) "_CMTimeMakeWithSeconds", referenced from: -[GADVideoPlayer seekToTime:] in GoogleMobileAds(GADVideoPlayer.o) "_CMTimeGetSeconds", referenced from: -[GADVideoP...Read more

eclipse - C++ dereferencing a instance variable pointer

Hello, im trying to learn C++ at the moment but i'm struggeling with pointers i wrote a class for a simple list with the instance variables:LinkedList *next;int val;However when i'm trying to dereference and get the value of next i get syntax error. The question is how can i derefernce the pointer correctly? If i don't use the pointer "this". My try was: LinkedList i;i.*next;and:i.(*next);Thank you for your help....Read more

Reading books information from txt file in C++?

I want to read books - their title, author and price from a txt file. The 3 properties of the book are separated by '|' - Title|Author|Book. However, I do not know exactly how to do this. I have the structure Book, with 3 elements. I want, for each line to read the book title, author and price, save them to the 3 variables of the structure respectively and print them on the console. I have tried to do this with the title only, but it print the whole line. I would like to ask how can I print for each books separately its author title and price?...Read more

iteration - Generating all R-digit numbers among N digits in C++ (combinations, iterative)?

I have a program, where I have to generate all R-digit numbers among N digits in C++, for example for N=3 (all digits from 1 to N inclusive) and R=2 the program should generate 12 13 21 23 31 32. I tried to do this with arrays as follows, but it does not seem to work correctly.#define nmax 20#include <iostream>using namespace std;int n, r;void print(int[]);int main(){ cin >> n; cin >> r; int a[nmax]; int b[nmax]; int used[nmax]; for (int p = 1; p <= n; p++) { //Filling the a[] array with numbers fro...Read more