Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I am trying to write a basic OpenGL loop (without GLWF and GLUT; only GLEW), which does nothing but clears the window.
However, the window keeps being white, the color of the window is not cleared to red.
Could you find the error why the code doesn't work?
Any other advice about my code? What can be made better?
/*Window is created using CreateWindowExA()*/
/* glewInit() etc */
RenderingContext = wglCreateContextAttribsARB(DeviceContext, 0, version_attribs);
if (!wglMakeCurrent(DeviceContext, RenderingContext))
{
OutputDebugStringA("Error\n");
exit(-1);
}
bool Running = true;
while (Running){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Simply clear the window with red
static const GLfloat red[] = { 1.0f, 0.0f, 0.0f, 1.0f };
glClearBufferfv(GL_COLOR, 0, red);
// here some other code
}
Any gl-command will be executed on the current context.
You use wglMakeCurrent(NULL, NULL); which means: "exclude all gl-commands for this thread"
Instead use wglMakeCurrent(this_window_device, the_context_I_want_to_use);
EDIT:
Also, the rendering is done to the back frame buffer (I'm supposing you are using a double buffer pixelformat). To show it into the window (front frame buffer) you need to call wglSwapBuffers.
EDIT 2:
I recomend you read the whole of wiki about creaating a context.
It shows an example of window and context creation.
Related
I'm migrating an application from SDL 1.2 to 2.0, and it keeps an array of dirty rectangles to determine which parts of its SDL_Surface to draw to the screen. I'm trying to find the best way to integrate this with SDL 2's SDL_Texture.
Here's how the SDL 1.2 driver is working: https://gist.github.com/nikolas/1bb8c675209d2296a23cc1a395a32a0d
And here's how I'm getting changes from the surface to the texture in SDL 2:
void *pixels;
int pitch;
SDL_LockTexture(_sdl_texture, NULL, &pixels, &pitch);
memcpy(
pixels, _sdl_surface->pixels,
pitch * _sdl_surface->h);
SDL_UnlockTexture(_sdl_texture);
for (int i = 0; i < num_dirty_rects; i++) {
SDL_RenderCopy(
_sdl_renderer, _sdl_texture, &_dirty_rects[i], &_dirty_rects[i]);
}
SDL_RenderPresent(_sdl_renderer);
I'm just updating the entire surface, but then taking advantage of the dirty rectangles in the RenderCopy(). Is there a better way to do things here, only updating the dirty rectangles? Will I run into problems calling SDL_LockTexture and UnlockTexture up to a hundred times every frame, or is that how they're meant to be used?
SDL_LockTexture accepts an SDL_Rect param which I could use here, but then it's unclear to me how to get the appropriate rect from _sdl_surface->pixels. How would I copy out just a small rect from this pixel data of the entire screen?
I have inserted custom gtk source gutter renderer pixbuf and I want to render icon on a specific line.
The reference API states that the interface is very similar to that on GtkTreeView, but doesn't work with a tree model.
So... how am I supposed to render data to a specific line if the GtkSourceGutter doesn't work with a tree model?
I checked every function in the entire library, every suggested api and child objects and nothing even hints about that.
It just doesn't make sense. The man page says that the GtkSourceGutterRendererPixbuf is used to display icon IN A CELL.
Doing gtk_source_gutter_renderer_pixbuf_set_pixbuf(renderer, pixbuf); will render the icon for all cells in the gutter.
And if the only way is to draw the pixbuf manually using cairo..what's the point in those renderers ?
How do I render pixbuf in a specific line using the gtksourcegutterrenderer?
I haven't worked with GtkSourceView, but I can give you some clues.
How it's done by GtkSourceView's author
First of all, we need some links:
GtkSourceGutterRendererMarks source code
GtkSourceGutterRendererPixbuf source code
GtkSourceGutterRenderer documentation
Let's start with GtkSourceGutterRendererPixbuf. From it's class_init method we find out, that it overrides only draw method. It's only purpose is to render a pixbuf or icon. Pure drawing.
However, GtkSourceGutterRenderer documentation says, that there is a query-data signal which can be used to tune Renderer's internal state. At this point we should take a look at GtkSourceGutterRendererMarks which is inherited from RendererPixbuf. It doesn't override draw, but overrides query_data. (For some reason GtkSourceGutterRendererClass is not described in the documentation. I don't know why.)
/* Read my comments. */
static void
gutter_renderer_query_data (GtkSourceGutterRenderer *renderer,
GtkTextIter *start,
GtkTextIter *end,
GtkSourceGutterRendererState state)
{
GSList *marks;
GdkPixbuf *pixbuf = NULL;
view = GTK_SOURCE_VIEW (gtk_source_gutter_renderer_get_view (renderer));
buffer = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
marks = gtk_source_buffer_get_source_marks_at_iter (buffer,
start,
NULL);
/* If there are marks, we find a pixbuf for one of them.
* Otherwise pixbuf is NULL. */
if (marks != NULL)
{
size = measure_line_height (view);
pixbuf = composite_marks (view, marks, size);
g_slist_free (marks);
}
/* Now tell parent class to render certain pixbuf
* It will render nothing if pixbuf is NULL. */
g_object_set (G_OBJECT (renderer),
"pixbuf", pixbuf,
NULL);
}
My recommendations.
You want to draw marks at certain lines (e.g. want to highlight current debugger line). If I were you, I would have inherited from RendererPixbuf, overriden query_data and use gtk_text_iter_get_line on GtkTextIter *start. Looks like that's the bare minimum.
Feel free to ask any further questions.
I personally cannot simply agree with the allegation that creating custom objects is easy. It isn't easy, not to everyone.
Mainly, because, this question is tagged c and people who don't know Object-Oriented programming might be unfamiliar with its concepts.
It is a matter of reading and practice.
So do not panic if you don't know how to, for instance create your own widget.
The easiest solution I can think of, doesn't involve creating your own renderer, but rather tell the renderer how to query rendering data.
Just connect the query-data signal on your GtkSourceGutterRenderer to a signal handler that looks like this:
G_MODULE_EXPORT void gutter_renderer_query_data (GtkSourceGutterRenderer *renderer, GtkTextIter *start, GtkTextIter *end, GtkSourceGutterRendererState state)
{
GtkSourceView* view = NULL;
GtkSourceBuffer* buffer = NULL;
GSList* marks = NULL;
GdkPixbuf* pixbuf = NULL;
view = GTK_SOURCE_VIEW(gtk_source_gutter_renderer_get_view(renderer));
buffer = GTK_SOURCE_BUFFER(gtk_text_view_get_buffer(GTK_TEXT_VIEW(view)));
marks = gtk_source_buffer_get_source_marks_at_iter(buffer, start, NULL);
if(marks != NULL)
{
char *category = gtk_source_mark_get_category(marks->data);
if(!g_strcmp0(category, "CERTAIN_CATEGORY")) /* See note 1) */
pixbuf = gtk_image_get_pixbuf(gtk_image_new_from_file("icon_file_here")); /* See note 2) */
g_slist_free(marks);
}
g_object_set(G_OBJECT(renderer), "pixbuf", pixbuf, "yalign", 0.5, NULL);
}
Notes:
GtkSourceMark shares the GtkSourceGutterRenderer interface so you might want to filter your other source marks, by specifying the category of a source mark that is applied to the certain line. Otherwise your custom renderer pixbuf will also be rendered left to your other source marks.
You should specify the exact pixbuf you want to render internally. Doing this, you won't have to call gtk_source_gutter_renderer_pixbuf_set_pixbuf() . You let the API do the resource handling.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
To be clear, I am coding in win32 and am not using MFC, wxWidgets or .net.
My issue is that I have a tab control with 2 tabs. For debugging purposes, each tab has a single STATIC window. When initialising, the following code is run:
createTabControl();
CreateStaticViewTab1();
CreateStaticViewTab1();
ShowWindow(Task1Tab, SW_SHOW);
Where
void createTabControl(){
TCITEM tie = { 0 };
hWndInputTab = CreateWindow(WC_TABCONTROL, L"Input", WS_VISIBLE | WS_CHILD , 10, 40, 300, 650, hWnd, (HMENU)TAB_INPUT, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
SetDefaultFont(hWndInputTab);
tie.mask = TCIF_TEXT;
TCHAR pszTab1[] = L"TAB 1";
tie.pszText = pszTab1;
TabCtrl_InsertItem(hWndInputTab, 0, &tie)
TCHAR pszTab2[] = L"TAB 2";
tie.pszText = pszTab2;
TabCtrl_InsertItem(hWndInputTab, 1, &tie)
}
void CreateStaticViewTab1(){
Task1Tab = CreateWindowEx(0,L"STATIC",L"Static Control on Tab1",WS_CHILD | WS_BORDER | SS_CENTER | SS_CENTERIMAGE, 75, 75, 200, 60, hWndInputTab,NULL, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE),NULL);
SetDefaultFont(Task1Tab);
}
void CreateStaticViewTab2(){
Task1Tab = CreateWindowEx(0,L"STATIC",L"Static Control on Tab2",WS_CHILD | WS_BORDER | SS_CENTER | SS_CENTERIMAGE, 75, 75, 200, 60, hWndInputTab,NULL, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE),NULL);
SetDefaultFont(Task2Tab);
}
In the WndProc, I am handling the WM_NOTIFY message. I have checked and can confirm that it executes correctly, calling the appropriate functions (ShowTab1() and ShowTab2()).
These two functions are designed to show and hide the appropriate tabs when the selection changes. They do so by the following:
void ShowTab1(){
ShowWindow(Task2Tab, SW_HIDE);
ShowWindow(Task1Tab, SW_SHOW);
}
void ShowTab2(){
ShowWindow(Task1Tab, SW_HIDE);
ShowWindow(Task2Tab, SW_SHOW);
}
These should - as I understand it - hide and show the correct tabs as appropriate.
My issue is that when the program is loaded, the correct tab (1) is shown. When tab 2 is clicked, the content of tab 1 (Task1Tab) is correctly hidden, however, the content of tab 2 (Task2Tab) is not correctly shown. When returning to tab 1, Task1Tab is correctly shown.
I cannot identify why there is a difference between the two pieces of code, as they are virtually identical.
nb. I have tested the code without the ShowWindow(Task1Tab, SW_SHOW) in the initialisation, this creates the tabs without any content and when tab 2 is clicked, nothing is shown, however, when tab 1 is clicked, Task1Tab is correctly shown.
You appear to have been caught out by some routine copy/paste errors. You call CreateStaticViewTab1 twice and never call CreateStaticViewTab2. And both CreateStaticViewTab1 and CreateStaticViewTab2 assign to Task1Tab. These mistakes would explain the behaviour that you observe.
Were your code to have performed any error checking, then that would have led you to the problem. Checking for errors would have revealed that ShowWindow(Task2Tab, ...) was failing because of an invalid window handle. So, another important lesson, beyond taking more care with the clipboard, is that you should always check for errors when calling Windows API functions.
Obvious issue - CreateStaticViewTab2() was never called.
I have been using the Future d3 but can not figure out how to change the series legend. In the older builds the legend could be changed like:
graf = plotter.AddLineGraph(new CompositeDataSource(xSrc, plot),
new Pen(brush, 4),
new PenDescription("myText" ));
but here the function call to AddLineGraph takes an object as argument and hence one can not specify the pendescription... Please does anyone know how to do this? This question was asked before here but did not get any answers. Any help would be highly appreciated. I have spend a lot of time on this and dont want to change to any other library just because of this small issue...
The above doesn't work with recent (2016) v0.4.0.
v0.4.0 uses the following syntax:
// For access to the Legend class
using Microsoft.Research.DynamicDataDisplay.Charts;
... snip ...
LineGraph lineGraph = new LineGraph(dataSource);
lineGraph.LinePen = new Pen(Brushed.Green, 1.0);
Legend.SetDescription(lineGraph, "The line label");
plotter.Children.Add(lineGraph);
... snip ...
v0.3.0 used the following syntax:
plotter.AddLineGraph(dataSource, pen, marker, new PenDescription("The line label"));
Ref: Changing and setting the Legend (LineGraph) Future of DynamicDataDisplay
Post http://d3future.codeplex.com/discussions/635917 provided the core fix.
I'm using Windows 7 with VC++ 2010
I'm trying to draw a simple point to a screen but it's not showing.
The screen is clearing to black so I know that I have a valid OpenGL context etc...
Basically my OpenGL code boils down to this (I don't have a depth buffer at this point):
glClear( GL_COLOR_BUFFER_BIT );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 45.0, 1018.0 / 743.0, 5.0, 999.0 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glColor4f( 1, 1, 1, 1 );
glPointSize( 100 );
glBegin( GL_POINTS );
glVertex2i( 0, 0 );
glEnd();
SwapBuffers( hdc );
The initialization code for OpenGL is this:
glClearColor( 0, 0, 0, 1 );
glShadeModel( GL_SMOOTH );
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
The problem is that nothing appears on the screen, the only thing that happens is the screen gets cleared.
Go through the following checklist (which is the general opengl checklist from delphigl.com (de_DE), which we usually give people to go through when they don't see anything):
Is your object accidentially painted in black? Try and change the glClearColor.
Do you have texturing enabled accidentially? Disable it before drawing with glDisable(GL_TEXTURE_2D).
Try disabling the following tests:
GL_DEPTH_TEST
GL_CULL_FACE
GL_ALPHA_TEST
Check whether your glViewport is setup correctly.
Try translating your Model View Matrix out of the near-clipping-plane (5.0 in your case) with glTranslatef(0, 0, -6.0)
There are several potential issues. The main problem will be how you are using the gluPerspective projection. gluPerspective is for perspectivic view and as such, it won't display anything at the (0, 0, 0) in View Coordinates. In your setup, you forbid displaying anything before (0, 0, 5) in View Coordinates (near clipping plane). I suggest setting your point to glVertex3f(0., 0., 10.) and try again. Another solution would be to use glTranslatef to move your View Coordinates around by more than 5 units.
Also glPointSize will probably not accept your value of 100, as common implementations are limited to a point size of 64.
For a good start with OpenGL, I'd also recommend reading up on Nehes Tutorials. They might not be State-Of-The-Art, but cover anything you're facing right now.
The problem was because I had called glDepthRange misunderstanding what it actually did, I was calling it like this: glDepthRange( nearPlane, farPlane ). (which was 5.0f and 999.0f) When I removed this call everything was able to draw correctly. Thankyou very much for your help. :)