LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-14-2017, 12:05 PM   #1
Neophyte1948
LQ Newbie
 
Registered: Dec 2010
Location: Woodchurch - Edge of Romney Marsh
Distribution: Mainly Ubuntu & Tiny core
Posts: 17

Rep: Reputation: 1
C graphics program - mystery message


I have modified some c code that I found on the net. It is the start of a simple card game and simply draws six rectangles;
#include<stdio.h>
#include<graphics.h>
int main()
{
int gd = DETECT,gm,xt=10,r;

initgraph(&gd,&gm,NULL);
for (r=0;r<6;r++){
rectangle(xt,10,xt+72,96);
xt+=80;
}
delay(5000);

closegraph();
return 0;
}



The program compiles and executes but sometimes I get the following message:
[xcb] Unknown sequence number while processing queue
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
pcard: ../../src/xcb_io.c:274: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.
I am at a loss to explain as sometimes it executes without any message at all.
Could some-one enlighten me please?
 
Old 01-14-2017, 12:16 PM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,234

Rep: Reputation: 5451Reputation: 5451Reputation: 5451Reputation: 5451Reputation: 5451Reputation: 5451Reputation: 5451Reputation: 5451Reputation: 5451Reputation: 5451Reputation: 5451
you gave almost no information, so would be nice to explain: what kind of c code did you modify? How did you compile your code?
please use [code]here comes your code[/code] to keep formatting.
http://catb.org/~esr/faqs/smart-questions.html
 
1 members found this post helpful.
Old 01-14-2017, 12:56 PM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,149

Rep: Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523
Well, initgraph, closegraph etc did work well in MS-Dos. For X Window, they might not be the best choice. I would try Java if I were you.
 
Old 01-14-2017, 03:31 PM   #4
Neophyte1948
LQ Newbie
 
Registered: Dec 2010
Location: Woodchurch - Edge of Romney Marsh
Distribution: Mainly Ubuntu & Tiny core
Posts: 17

Original Poster
Rep: Reputation: 1
Pan64 :: What information do you need? I used the GNU compiler - gcc -o "file" -lgraph "file.c"
In the code (pasted from the source) Only the 'for loop' is mine.
The problem is exactly as stated.
I have no more information apart from Linux version is Ubuntu 16.04.
for future reference, What specific information should I have included?

NevernTeve At 69 I have no wish to embark on learning a new language !! Ihave already written most of the underlying code( in c)
The code above is an experiment to produce a visual accompaniment to this.
 
Old 01-14-2017, 11:15 PM   #5
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,149

Rep: Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523
http://savannah.nongnu.org/projects/libgraph/
Seems to be outdated/abandoned...
 
Old 01-15-2017, 05:21 PM   #6
DeeDeeK
Member
 
Registered: Jan 2016
Distribution: Ubuntu 14.04
Posts: 37

Rep: Reputation: Disabled
stick with C programming. That's where the power is and it makes your smarter

Are you using XCB or Xlib-xcb, or Xlib? I see [xcb] preceding each message you listed.

Does your code have an event loop responding to x events? Might sound like a silly question but it's very possible to ignore x events. The word 'queue' makes me wonder whether you're dealing with events. Really, more information is needed here. Post your code? Description of which x calls, which headers you're including? Do you go fullscreen or in an on-screen window? Do you interact with the window manager? So many questions come to mind!

Perhaps use just xcb calls, instead of xlib? xcb is thread safe.

Threaded code is somewhat nondeterministic so having code which sometimes works and sometimes doesn't isn't a rare problem.

Neophyte1948 says
Quote:
NevernTeve At 69 I have no wish to embark on learning a new language !! Ihave already written most of the underlying code( in c)
The code above is an experiment to produce a visual accompaniment to this.
I've no idea why we C programmers are so frequently told to change languages as an answer to questions about how to make our C code run correctly or questions about error messages we get, our code's unpredictable behavior, etc.

It's like saying "how do I change the oil in my car?" and being told "buy an electric car." Non-sequitor. It's not even an answer, because it isn't meaningfully related to any question we've asked.

That said, it is very hard to guess the cause of the messages without seeing any code. Have you used GDB? I am not smart enough to figure it out, myself, but I read good things. I use Valgrind a lot because it'll tell me where my code messed up many times.

I do a lot of graphics programming and finally made my own little library just using primitive-just drawing pixels or rectangles, actually, with XCB calls.
 
2 members found this post helpful.
Old 01-16-2017, 07:35 AM   #7
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,149

Rep: Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523
Nonetheless, you could read the Original Post: the complete program is pasted; it uses a TurboC-compatibility library called libgraph.so

@Neophyte1948: Please edit your first post and add [code] and [/code] tags.

Last edited by NevemTeve; 01-16-2017 at 09:37 AM.
 
Old 01-16-2017, 02:15 PM   #8
Neophyte1948
LQ Newbie
 
Registered: Dec 2010
Location: Woodchurch - Edge of Romney Marsh
Distribution: Mainly Ubuntu & Tiny core
Posts: 17

Original Poster
Rep: Reputation: 1
DeeDeeK

I appreciate your comments no end. Truth to tell I have been stumbling from one web-site to another trying to find a simple linux graphics package, and have installed all sorts of libraries in response to various suggestions as to why the simple things I am trying to achieve have all failed. I have no experience in graphics of any kind but have some basic c coding practice. I intend(ed) to write a program for a friend to practice playing the "cribbage" card game.
I suspect that the code that I copied uses some underlying calls to the X-server which have not been properly terminated but I have no Idea what. Perhaps you could give me some useful links, Ultimately I wish to place six .jpg images of cards on a green-coloured screen and Place a scoring peg-board in the centre. I would be happy with drawing the cards etc. from scratch, as it would all be a good learning experience for me.

Thanks in hopeful anticipation
Neophyte 1948

I am not sure how to add tags to my original post.
 
1 members found this post helpful.
Old 01-16-2017, 02:56 PM   #9
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,583
Blog Entries: 11

Rep: Reputation: 3601Reputation: 3601Reputation: 3601Reputation: 3601Reputation: 3601Reputation: 3601Reputation: 3601Reputation: 3601Reputation: 3601Reputation: 3601Reputation: 3601
Quote:
Originally Posted by Neophyte1948 View Post
I am not sure how to add tags to my original post.
To place your code snippets inside [CODE]...[/CODE] tags for better readability, you may type those yourself or click the "#" button in the edit controls.
 
Old 01-16-2017, 09:08 PM   #10
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
@Neophyte1948 - Take a look at SFML: https://www.sfml-dev.org/ It has very good documentation and tutorials.

I have only dabbled with it in c++ but it has c bindings: http://www.sfml-dev.org/download/csfml/

EDIT: Forgot to mention it is in the repos: http://packages.ubuntu.com/search?keywords=sfml

Last edited by norobro; 01-16-2017 at 09:31 PM.
 
1 members found this post helpful.
Old 01-17-2017, 05:04 PM   #11
Neophyte1948
LQ Newbie
 
Registered: Dec 2010
Location: Woodchurch - Edge of Romney Marsh
Distribution: Mainly Ubuntu & Tiny core
Posts: 17

Original Poster
Rep: Reputation: 1
Thanks to all who responded to my post. I think I will have to remove some spurious libraries and make a fresh start!
Special thanks to
"DeeDeeK" for your support and sugestions on my orignal post, and to noboro for the pointer (excuse pun),to SFML it looks promising - have not come across that in my searches.
Hopefully the next time I have to bother you good people I will be able to ask a question in a more answerable form.
 
Old 01-17-2017, 05:26 PM   #12
DeeDeeK
Member
 
Registered: Jan 2016
Distribution: Ubuntu 14.04
Posts: 37

Rep: Reputation: Disabled
I quote Neophyte1948:
Quote:
X-server which have not been properly terminated but I have no Idea what. Perhaps you could give me some useful links, Ultimately I wish to place six .jpg images of cards on a green-coloured screen and Place a scoring peg-board in the centre. I would be happy with drawing the cards etc. from scratch, as it would all be a good learning experience for me.
I'm thinking, that since you wouldn't mind drawing the cards yourself, and it seems that you're interested in expanding your horizons, that a little Xlib and XCB programming would be fun. I'm NOT trying to say this is the 'best' or even most sensible way. It's what I've explored and I found fun and challenging. I don't like lots of high level libraries 'helping' me but really hiding a lot of the details and information I'm interested in learning, for ease and expediency's sake-both valid motivations. But not MY motivation.

YouTube resists allowing me to view anything on Firefox and I'm too annoyed with it to fix the problem. I use video download helper to download anything I want to see, to watch later anyhow. BUT, here are two URLs of recordings of the output of some test code of mine. You'll see my name there and there will be a few more examples for you to see of what you can do with only the information you'll find at freedesktop.org's XCB tutorial pages. I think. You'd need to know how to draw circles and the Newton's formula for gravity and, umm, one for elastic collisions. They're out there to be found on the web.

https://www.youtube.com/watch?v=xeoXl3wzWD8

https://www.youtube.com/watch?v=GcVE2tUhi1k

I'm going to list some URLs, and I'll be happy to think it through more and post more info. I'm actually thinking of writing some "how I taught myself to to do" articles (as opposed to "how-to" articles) documenting my learning process. I like C, I don't want to use any other language, and I want to do it the hard way. More power and ultimately more flexibility as available that way.


https://www.freedesktop.org/wiki/

https://www.x.org/releases/X11R7.7/d...ial/index.html

I hope you check out the Xlib manual in HTML by Tronche I mentioned earlier.

I stripped out the init from the library I'm working on, and simplified it. It compiles but I haven't tested it yet.

I in my still incomplete libraries I use pixmaps and do a sort of double buffering and animation and all sorts of jazz, just using the xcb drawing primitives. Actually, just using the filled rectangle primitive. I do all the math and stuff myself. I could use xcb_point_t's instead of rectangles, but I like drawing with big blocky faux-pixels. I learned my first graphics programming on an Atari 400 with 160x96, 4 color or 320x192 2 color(black and white usually) graphics, y'see.

Code:
#include <X11/Xatom.h>
#include <X11/Xlib-xcb.h>
#include <xcb/xcb_atom.h>



xcb_window_t	window;

xcb_gcontext_t 	*globalcolorarray;



void //  sets up the window
little_init(int width, int height, int numcolors){

	dpy = XOpenDisplay(NULL);
	connection = XGetXCBConnection(dpy);
	int scrnnumber = DefaultScreen(dpy);
	int fullscreen = no;

	if((!height)||(!width)){
		fullscreen = yes;
		width = (int)DisplayWidth(dpy, scrnnumber);
		height = (int)DisplayHeight(dpy, scrnnumber);
	}
	xRes = width;
	yRes = height;

	uint32_t value_mask;
	uint32_t value_list[2];

	srand((int)clock());

	globalcolorarray = calloc (numcolors, sizeof(xcb_gcontext_t));

	//connection = xcb_connect (NULL, NULL);
	screen = xcb_setup_roots_iterator (xcb_get_setup (connection)).data;

	value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK ;

	value_list[0] = screen->white_pixel;
	value_list[1] =
		XCB_EVENT_MASK_EXPOSURE 			|	XCB_EVENT_MASK_BUTTON_PRESS		|
		XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION |
		XCB_EVENT_MASK_ENTER_WINDOW   | XCB_EVENT_MASK_LEAVE_WINDOW   |
		XCB_EVENT_MASK_KEY_PRESS	  | XCB_EVENT_MASK_KEY_RELEASE ;

	window = xcb_generate_id (connection);

	xcb_create_window (connection,
		XCB_COPY_FROM_PARENT,window, screen->root,
		0,0,	xRes, yRes,
		0, XCB_WINDOW_CLASS_INPUT_OUTPUT,
		screen->root_visual, value_mask, value_list
	);

	if(fullscreen){
		Atom atoms[2] = { XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False), None };
		XChangeProperty(dpy, window, XInternAtom(dpy, "_NET_WM_STATE", False),
                  XA_ATOM, 32, PropModeReplace, (unsigned char*) atoms, 1);
	}
	xcb_map_window(connection, window);

	char *title = "[your title goes here]";
	xcb_change_property (connection, XCB_PROP_MODE_REPLACE, window,
			XCB_ATOM_WM_NAME, XCB_ATOM_STRING,8, strlen(title), title);
	char *iconTitle = "[your title here]";
	xcb_change_property (connection, XCB_PROP_MODE_REPLACE, window,
		XCB_ATOM_WM_ICON_NAME, XCB_ATOM_STRING, 8, strlen(iconTitle), iconTitle);

	value_mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
	value_list[1]= 0;
	globalcolorarray[0]=xcb_generate_id(connection);
	defaultgraphicscontext = xcb_generate_id(connection);

	xcb_create_gc (connection, defaultgraphicscontext, window, value_mask, value_list);
	xcb_create_gc (connection, globalcolorarray[0], window, value_mask, value_list);

	value_mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES ;//| XCB_GC_FONT ;
	value_list[0] = screen->black_pixel;
	value_list[1]= 0;


	whitegraphicscontext = xcb_generate_id(connection);
	globalcolorarray[1] = xcb_generate_id(connection);
	value_list[0] = screen->white_pixel;

	xcb_create_gc (connection, whitegraphicscontext, window, value_mask, value_list);
	xcb_create_gc (connection, globalcolorarray[1], window, value_mask, value_list);

} //little_init
Get that function working right and then figure out a struct which works with this snippet:
Code:
		while (temp_rectlist){
			xcb_poly_fill_rectangle (connection, window, temp_rectlist->gc,
				temp_rectlist->numrects, temp_rectlist->rectarray
			);
			temp_rectlist = temp_rectlist->nextcolor;
		}
the struct temp_rectlist has a xcb_gcontext_t, an int, and an xcb_rectangle_t* in it.

the declaration
Code:
xcb_gcontext_t *globalcolorarra;y
can be declared
Code:
xcb_gcontext_t globalcolorarray[n];
if you like.

Instead of changing the foreground color of the graphics context I'm using, I just make a palette of different graphics contexts in an array. I've made over a million individual xcb_gcontext_t's and not run out of space. It just takes a while. But then you can make a function like
Code:
plot(int color, short x, short y, xcb_window_t window);
using int color as an index into your array of pre-prepared graphics contexts.

I'll leave it to you and those URLs to figure how to make it work. I'd learn Bresenham's line drawing a circle algorithms and I bet you can figure out rectangles and so forth from there ;-)

I started this graphics project to learn C and learn about X11 graphics, and how to use GCC and program on a GNU/Linux system, so I'm a real bare-bones guy. If you find junk in that code, or if it doesn't fully work, that's OK. I didn't try to give you a perfect example. I find using xlib-xcb to be fun and challenging, and I bet you'll enjoy learning to create analogous functions to the ones you find in graphics.h!

Remember if someone discourages you from learning something to ignore them! And take advice from people who can show you something. That's how I'm learning what I'm learning. Rather than listen when someone tells me "it won't work that way" I ask myself "how can it work ALMOST that way."

Last edited by DeeDeeK; 01-17-2017 at 05:37 PM. Reason: to add a URL showing a youtube example of my work
 
Old 01-17-2017, 10:05 PM   #13
DeeDeeK
Member
 
Registered: Jan 2016
Distribution: Ubuntu 14.04
Posts: 37

Rep: Reputation: Disabled
I forgot to mention I'd checked out your posted code and since the workings of graphics.o or graphics.c (to go with graphics.h I'm imagining) it's impossible for me to guess at the error other than to say I'd bet dollars to donuts the mistake is not yours.

I jammed all the code in my last post to encourage you to spread your wings and explore. Of course if you're more linearly oriented, and just want to write the game straightaway, what I've suggested might be a bit circuitous.

You could use GTK+ and Cairo. Another learning curve. But that graphics.h is a bit of a dead end.

I've learned a bit about them. And also how to use Cairo with Xlib-xcb. You can tell it to render all it's fancy antialiased graphics in a window or pixmap a la XCB.

Here's another source of information I've found very useful: http://zetcode.com/

Last edited by DeeDeeK; 01-17-2017 at 10:08 PM. Reason: adding URL to zetcode
 
1 members found this post helpful.
Old 01-18-2017, 04:38 AM   #14
Neophyte1948
LQ Newbie
 
Registered: Dec 2010
Location: Woodchurch - Edge of Romney Marsh
Distribution: Mainly Ubuntu & Tiny core
Posts: 17

Original Poster
Rep: Reputation: 1
Sorted to my satisfaction [SOLVED]
Is it me or would it make sense to add a [solved] button at the bottom of the post with the other options?
 
Old 01-18-2017, 06:31 AM   #15
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,259
Blog Entries: 13

Rep: Reputation: 4350Reputation: 4350Reputation: 4350Reputation: 4350Reputation: 4350Reputation: 4350Reputation: 4350Reputation: 4350Reputation: 4350Reputation: 4350Reputation: 4350
Quote:
Originally Posted by Neophyte1948 View Post
Sorted to my satisfaction [SOLVED]
Is it me or would it make sense to add a [solved] button at the bottom of the post with the other options?
Up on the right, Thread Tools is a pull down menu in the webpage. In there is an option for you to mark this thread as Solved.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] mystery program darthaxul Linux - Networking 2 12-21-2013 04:06 PM
Name of a graphics program? clifford227 Linux - Software 2 08-07-2012 03:27 PM
Boot Up Program Mystery james3545 Linux - Newbie 6 10-14-2008 04:43 AM
How to do C graphics program anupamjamatia Programming 8 07-03-2008 09:44 AM
Graphics program(s)? lt1derful Linux - Software 6 07-10-2003 10:03 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration